Introduction
SQL Server 2008 has introduced the new feature compound operator. Compound operators are available in other programming languages like C# etc. Compound Assignment Operators are operators where variables are operated upon and assigned on the same line.
The following Operators are supported as compound operators.

Examples
+= Operator
DECLARE @addvalue int = 53;
SET @addvalue += 20 ;
PRINT 'Add value :' + CAST(@addvalue AS VARCHAR);
--Result : Add value :73
DECLARE @concString VARCHAR(50) = 'Jignesh';
SET @concString += ' Trivedi' ;
PRINT 'Output :' + @concString;
--Result : Output :Jignesh Trivedi
-= Operator
DECLARE @subValue int = 99;
SET @subValue -= 2 ;
PRINT 'subtract value :' + CAST(@subValue AS VARCHAR);
--Result : subtract value :97
*= Operator
DECLARE @mulValue int = 75;
SET @mulValue *= 20 ;
PRINT 'Multiplication :' + CAST(@mulValue AS VARCHAR);
--Result : Multiplication :1500
/= Operator
DECLARE @divValue NUMERIC(8,2) = 27;
SET @divValue /= 2.5 ;
PRINT 'Division :' + CAST(@divValue AS VARCHAR);
--Result : Division :10.80
%= Operator
DECLARE @modulo int = 25;
SET @modulo %= 5 ;
PRINT 'Modulo :' + CAST(@modulo AS VARCHAR);
--Result : Modulo :1
&= Operator
DECLARE @bitAnd int = 90;
SET @bitAnd &= 13 ;
PRINT 'Bitwise AND Operation:' + CAST(@bitAnd AS VARCHAR);
--Result : Bitwise AND Operation:8
^=Operator
DECLARE @bitExOr int = 244;
SET @bitExOr ^= 20 ;
PRINT 'Bitwise Exclusive OR Operation:' + CAST(@bitExOr AS VARCHAR);
--Result : Bitwise Exclusive OR Operation:224
|= Operator
DECLARE @bitOR int = 270;
SET @bitOR |= 25 ;
PRINT 'Bitwise OR Operation:' + CAST(@bitOR AS VARCHAR);
--Result : Bitwise OR Operation:287
Conclusion
The Compound Operators feature is enhanced in SQL Server. They are like compound operators in languages like C, C++, and C #. Compound operators combine operators with another operator.

Pankajkumar PatelPosted Feb 3, 2023, 4:14 AM
Simple and easy, really well explained!
Jignesh TrivediPosted Jul 2, 2013, 11:36 PM
from example DECLARE @addvalue int = 53; SET @addvalue = 20 ; PRINT 'Add value :' CAST(@addvalue AS VARCHAR); -- if you face problem let me know.
Jignesh TrivediPosted Jul 2, 2013, 11:36 PM
hi, from your comment looks, you are not run whole block of query...so please run whole block of query.
Ramesh RPosted Jul 2, 2013, 11:44 AM
Msg 139, Level 15, State 1, Line 0 Cannot assign a default value to a local variable. Msg 137, Level 15, State 2, Line 3 Must declare the scalar variable "@addvalue".
Ramesh RPosted Jul 2, 2013, 11:44 AM
Hi Jignesh, I am unable to execute the above queries in SQL server 2008.Iam getting below error message.