Compound Operators in SQL Server
Compound
Assignment Operators in SQL Server 2008
Compound
assignment operator means an operator combined with another operator.
We have used such assignment operators in C++ and C#. This Compound
Assignment Operator is introduced in SQL Server 2008.
The
compound assignment operators; supported in SQL Server 2008 are:
|
Compound Assignment
Operator
|
Description
|
|
+=
|
Add and assign
|
|
-=
|
Subtract and assign
|
|
*=
|
Multiply and assign
|
|
/=
|
Divide and assign
|
|
%=
|
Modulus and assign
|
|
&=
|
Bitwise AND and assign
|
|
|=
|
Bitwise OR and assign
|
|
^=
|
Bitwise XOR and assign
|
Compound
Assignment Operator - Add and Assign Example:
Declare @Compvar int
Set @Compvar = 3
--using Compound assignment operator
Set @Compvar+=7
Select @ Compvar as CompResult
Go
Output will be
MyResult
10
(1 row(s) affected)
In
the above example, the compound assignment operator added the value 7
to the existing value of the variable @Compvar and assigned the
resulting value to @Compvar.