This site has shown stored procedure and function to calculate factorial with SQL. Although the logic is so simple as extracting one from previous argument and multiplying to it, it requires high cost of computing power. Therefore, the maximum of argument is restricted to so relatively small integer. In this article, you can calculate factorial with converting argument to natural logarithm, adding them and re-converting it to power of e, the base of natural logarithm.
CREATE PROCEDURE [dbo].[LOG_FACT] @SrcNumber FLOAT AS BEGIN DECLARE @DesNumber FLOAT SET @DesNumber = LOG(1) WHILE @SrcNumber > 0 BEGIN SET @DesNumber = @DesNumber + LOG(@SrcNumber) SET @SrcNumber = @SrcNumber - 1 END SELECT EXP(@DesNumber) END
Maximum of argument is 170.
EXEC LOG_FACT 170; 7.25741561530971E+306