SET @variable (TSQL Statement)

sets the variable to the specified value.

Syntax

SET @variable = expression

SET @variable += expression
SET @variable -= expression
SET @variable *= expression
SET @variable /= expression
SET @variable %= expression
SET @variable &= expression
SET @variable |= expression
SET @variable ^= expression

Arguments

@variable
is the name of a variable of any type.
expression
is an expression of any type.

Compound Assignment Operators

The operator += is a shortcut for add and assign.

SET @a += 123;       -- is the same as
SET @a  = @a + 123;

The same can be said for the other compound operators.

Remarks

The variable should have been created previously by a DECLARE @variable statement. Else, an error is raised.

RSQL doesn’t modify the value of @@ROWCOUNT.
But with MS SQL Server, this statement sets the value of rowcount to 1.

Examples

DECLARE @a VARCHAR(20);

SET @a = 'Hello';
PRINT @a;

SET @a += ' World';    -- same as SET @a = @a + ' World'
PRINT @a;

The result is:

Hello
Hello World