Using SELECT to Assign Variables : Variable Select « Transact SQL « SQL Server / T-SQL Tutorial






3> DECLARE @MyNumber1 Int, @MyNumber2 Int, @MyResult1 Int, @MyResult2 Int
4> SELECT @MyNumber1 = 144, @MyNumber2 = 121
5> 
6> SELECT @MyResult1 = SQRT(@MyNumber1), @MyResult2 = SQRT(@MyNumber2)
7> 
8> SELECT @MyResult1, @MyResult2
9> GO

----------- -----------
         12          11

(1 rows affected)








20.3.Variable Select
20.3.1.Syntax for Variable Assignment with the SELECT Statement
20.3.2.Using SELECT to Assign Variables
20.3.3.An alternate syntax for setting a variable's value in a select list
20.3.4.multiple variables can be assigned values in a single operation.
20.3.5.Creating a Comma Delimited List using SELECT
20.3.6.Use select to output a variable
20.3.7.Example of a Variable Not Updated Due to No Rows Being Returned
20.3.8.Assignment with a Subquery