= (Assignment) (TSQL Operator)

Assigns the value of an expression to a variable.

Syntax

@variable = expression

@variable += expression        is a shortcut for   @variable = @variable + expression
@variable -= expression        is a shortcut for   @variable = @variable - expression
@variable *= expression        is a shortcut for   @variable = @variable * expression
@variable /= expression        is a shortcut for   @variable = @variable / expression
@variable %= expression        is a shortcut for   @variable = @variable % expression
@variable &= expression        is a shortcut for   @variable = @variable & expression
@variable |= expression        is a shortcut for   @variable = @variable | expression
@variable ^= expression        is a shortcut for   @variable = @variable ^ expression

Arguments

variable
is a variable of any type.
expression
is an expression of any type.

Remarks

If type of expression is not the same as the type of variable, an implicit cast is performed.

Examples

DECLARE @a INT;

SET @a = 12345.67;  -- the expression of type NUMERIC is implicitly cast to INT
PRINT @a;

SET @a += 40000;
PRINT @a;

The result is:

12345
52345