I am a beginner in SQL Functions. What is the best way to create a function for factorial in SQL Server- Say 10!
Here is an other method to calculate factorial value of an integer in SQL Server
create function sqlFactorial (@int int)
returns int
begin
declare @factorial bigint = 1
select @factorial = @factorial * i from dbo.NumbersTable(1,@int,1)
return @factorial
end
You need to use a SQL numbers table for this solution. The Select statement updates the declared integer variable for each row in the FROM part with multiplying it with the ordered integer values