In this example we will create a procedure that calculates power of given number.
1 2 3 4 5 6 7 8 9 10 |
Create Procedure myPower(@num int,@pow int, @result int output) As Begin Declare @i int = 0; Set @result = 1 while(@i<@pow) Begin Set @result = @result * @num Set @i += 1 End End |
The Usage Of The Procedure
1 2 3 |
Declare @result int Execute myPower 3,4,@result output Select @result |
Result: 81
1 2 3 |
Declare @result int Execute myPower 2,5,@result output Select @result |
Result: 32
1 2 3 |
Declare @result int Execute myPower 5,3,@result output Select @result |
Result: 125