SET
Statement
Assigns a new value to a previously declared variable. The new value does not need
to be of the same type as the previous value. It is an error to assign a value to an undeclared variable. Use the
DECLARE
statement to declare variables.
Syntax
SET variable-name = new-value;
Parameters
- variable-name: identifier
A name beginning with an at sign (@
), dollar sign ($
), or colon (:
). The name must have been previously declared in this script. - new-value: scalar
The value to assign to the variable. It may be a scalar expression or a parentheses-enclosedSELECT
statement.
Example
DECLARE @a = 1;
SET @a = 2;