Using SET to Assign Variables : Set Variables « Transact SQL « SQL Server / T-SQL






Using SET to Assign Variables

1>
2> -- Using SET to Assign Variables
3>
4> -- Capture the return value for the same function.
5>
6> DECLARE @MyNumber Int, @MyResult Int
7> SET @MyNumber = 144
8>
9> -- Assign the function result to the variable:
10> SET @MyResult = SQRT(@MyNumber)
11> -- Return the variable value
12> SELECT @MyResult
13> GO

-----------
         12

(1 rows affected)
1>

           
       








Related examples in the same category

1.Assign value to a variable
2.Set value from select statement to a variable
3.Assign value returned from a aggregate function to a variable with set statement