In this tutorial we will write “Stored Procedure” calculates the factorial of a number. That is specified at below.
1 2 3 4 5 6 7 8 9 10 11 12 |
Create procedure factor(@number int) as begin Declare @i int = 1,@result int=1 while (@i<=@number) Begin Set @result = @result * @i Set @i += 1 End Select @result End |
You must execute the code ebove and get succesful message. Then By running the following code, you can calculate the factorial of the number you want.
1 2 3 |
Execute factor 5 |
Result:120