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 |
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 |
Execute factor 5 |
Result::120
1 |
Execute factor 10 |
Result::3628800
Write a procedure to calculate factorial of a number entered by user.
1 |
Execute factor 6-- The user entered 6 value |
Result: 720