Create Stored Procedure
CREATE PROCEDURE Factorial_ap
@Number Integer,
@RetVal Integer OUTPUT
AS
BEGIN
DECLARE @In Integer, @Out Integer
IF @Number != 1
BEGIN
SELECT @In = @Number-1
EXEC Factorial_ap @In, @Out OUTPUT
SELECT @RetVal = @Number * @Out
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN @RetVal
END
GO
Call the Stored Procedure
DECLARE @RESULT Integer
SET @RESULT = 0
EXEC Factorial_ap 5, @RESULT OUTPUT
PRINT @RESULT