递归SQL函数,< =运算符不起作用

时间:2015-12-26 13:37:18

标签: sql-server-2012-express

我只是想知道为什么会这样。但我所评论的内容并不奏效。

ALTER PROC spFactorial
    @ValueIn int,
    @ValueOut int OUTPUT
AS
    DECLARE @InWorking int;
    DECLARE @OutWorking int;

    IF @ValueIn <> 1            -- this <= doesn't work??
    BEGIN
         SELECT @InWorking = @ValueIn - 1;

         EXEC spFactorial @InWorking, @OutWorking OUTPUT;

         SELECT @ValueOut = @ValueIn * @OutWorking;
    END
    ELSE
    BEGIN
        SELECT @ValueOut = 1;
    END

    RETURN;
GO

DECLARE @WorkingOut int;
DECLARE @WorkingIn int;
SELECT @WorkingIn = 3;

EXEC spFactorial @WorkingIn, @WorkingOut OUTPUT;

PRINT CAST(@WorkingIn AS varchar ) + ' factorial is '
+ CAST(@WorkingOut AS VARCHAR );

IF @ValueIn <= 1无效 - 为什么?

在C#或java中它可以工作。

谢谢

1 个答案:

答案 0 :(得分:0)

<= is not an operator in SQL. In c# and Java it is. 

对于Sql中的&lt; =运算符功能,您可以执行此操作

IF(@value < 1 OR @value = 1)