Systems Engineering and RDBMS

Compound Assignment Operators in SQL Server 2008

Posted by decipherinfosys on January 15, 2008

Continuing in the series on the new features in SQL Server 2008, here is another small little tid-bit. SQL Server 2008 (tested in CTP5) supports the compound assignment operators. Here is a working example of those operators:

declare @i int
set @i = 100

/**************************
Addition and assignment
***************************/
set @i += 1
select @i

———–
101

/**************************
Subtraction and assignment
***************************/
set @i -= 1
select @i

———–
100

/**************************
Multiplication and assignment
***************************/
set @i *= 2
select @i

———–
200

/**************************
Division and assignment
***************************/
set @i /= 2
select @i

———–
100

/**************************
Addition and assignment
***************************/
set @i %= 3
select @i

———–
1

/**************************
xor operation and assignment
***************************/
set @i ^= 2
select @i

———–
3

/**************************
Bitwise & operation and assignment
***************************/
set @i &= 2
select @i

———–
2

/**************************
Bitwise | operation and assignment
***************************/
set @i |= 2
select @i

———–
2

One Response to “Compound Assignment Operators in SQL Server 2008”

  1. […] can also see the new syntax of ” *= ” for the multiplication of the data – that is the compound assignment operator in SQL Server […]

Sorry, the comment form is closed at this time.

 
%d bloggers like this: