Using SELECT to Assign Variables : Assign Value « Transact SQL « SQL Server / T-SQL






Using SELECT to Assign Variables


1> -- Using SELECT to Assign Variables
2>
3> DECLARE @MyNumber1 Int, @MyNumber2 Int, @MyResult1 Int, @MyResult2 Int
4>
5> SELECT @MyNumber1 = 144, @MyNumber2 = 121
6> -- Assign the function result to the variable:
7>
8> SELECT @MyResult1 = SQRT(@MyNumber1), @MyResult2 = SQRT(@MyNumber2)
9> -- Return the variable value
10> SELECT @MyResult1, @MyResult2
11> GO

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

(1 rows affected)
1>
2>
           
       








Related examples in the same category

1.Assign value from select statement to a variable
2.Assign query result to a variable
3.Dynamically set the number of rows returned