3> CREATE FUNCTION fn_factorial (@param decimal(38, 0) )
4> RETURNS decimal(38, 0)
5>
6> AS
7> BEGIN
8> IF (@param < 0 OR @param > 32) RETURN (0)
9> RETURN (CASE
10> WHEN @param > 1 THEN @param * dbo.fn_factorial(@param - 1)
11> ELSE 1
12> END)
13> END
14> GO
1>
2> SELECT factorial = dbo.fn_factorial(10)
3> GO
factorial
----------------------------------------
3628800
|