sql 存储过程 递归

CREATE PROC  [dbo].[usp_spFactorial]
@InputValue INT,
@OuputValue INT OUTPUT
AS
BEGIN
     DECLARE @InValue    INT;
     DECLARE @OutValue    INT;
       IF(@InputValue!=0)
            BEGIN
                 SET @InValue = @InputValue - 1;
                 EXEC usp_spFactorial @InValue,@OutValue OUTPUT;
                 SELECT @OuputValue = @InputValue + @OutValue;
            END
        ELSE
            BEGIN
            SET @OuputValue = 0;
            END
END

 

posted @ 2014-01-25 11:29  zhangsir  阅读(397)  评论(0编辑  收藏  举报