| title | Compound Operators (Transact-SQL) | ||
|---|---|---|---|
| description | Compound operators execute some operation and set an original value to the result of the operation. | ||
| author | rwestMSFT | ||
| ms.author | randolphwest | ||
| ms.date | 05/07/2026 | ||
| ms.service | sql | ||
| ms.subservice | t-sql | ||
| ms.topic | reference | ||
| ms.custom |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
||
| monikerRange | =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDE SQL Server Azure SQL Database Azure SQL Managed Instance Fabricsqldb]
Compound operators execute some operation and set an original value to the result of the operation. For example, if a variable @x equals 35, then @x += 2 takes the original value of @x, adds 2, and sets @x to that new value (37).
[!INCLUDE tsql] provides the following compound operators:
| Operator | Link to more information | Action |
|---|---|---|
| += | Addition assignment | Adds some amount to the original value and sets the original value to the result. |
| -= | Subtraction assignment | Subtracts some amount from the original value and sets the original value to the result. |
| *= | Multiplication assignment | Multiplies by an amount and sets the original value to the result. |
| /= | Division assignment | Divides by an amount and sets the original value to the result. |
| %= | Modulus assignment | Divides by an amount and sets the original value to the modulo. |
| &= | Bitwise AND assignment | Performs a bitwise AND and sets the original value to the result. |
| ^= | Bitwise exclusive OR assignment | Performs a bitwise exclusive OR and sets the original value to the result. |
| |= | Bitwise OR assignment | Performs a bitwise OR and sets the original value to the result. |
expression <operator> expression
Any valid expression of any one of the data types in the numeric category.
Returns the data type of the argument with the higher precedence. For more information, see Data type precedence.
For more information, see the topics related to each operator.
The following examples demonstrate compound operations.
DECLARE @x1 AS INT = 27;
SET @x1 += 2;
SELECT @x1 AS Added_2;
DECLARE @x2 AS INT = 27;
SET @x2 -= 2;
SELECT @x2 AS Subtracted_2;
DECLARE @x3 AS INT = 27;
SET @x3 *= 2;
SELECT @x3 AS Multiplied_by_2;
DECLARE @x4 AS INT = 27;
SET @x4 /= 2;
SELECT @x4 AS Divided_by_2;
DECLARE @x5 AS INT = 27;
SET @x5 %= 2;
SELECT @x5 AS Modulo_of_27_divided_by_2;
DECLARE @x6 AS INT = 9;
SET @x6 &= 13;
SELECT @x6 AS Bitwise_AND;
DECLARE @x7 AS INT = 27;
SET @x7 ^= 2;
SELECT @x7 AS Bitwise_Exclusive_OR;
DECLARE @x8 AS INT = 27;
SET @x8 |= 2;
SELECT @x8 AS Bitwise_OR;