**In this tutorial we will learn how to Create sql function to calculate the factorial with example.**

| Create function factor(@number int) returns int as begin Declare @i int = 1,@result int=1 while (@i<=@number) Begin Set @result = @result * @i Set @i += 1 End return @result End |

First you must run the code ebove. Then you can calculate any number of factorial with following code.

Result::3628800

**CLICK HERE TO SEE MORE EXAMPLE ABOUT SCALAR VALUED FUNCTIONS**

__YOU MAY WANT TO SEE OUR ALL EXAMPLES PAGE, THEN CLICK HERE__

### Like this:

Like Loading...

*Related*