0

好吧,显然这不起作用。我收到“'=' 附近的语法错误”错误。是否可以在存储过程中多次更改变量的值?

与此示例类似:

    DECLARE @columnCounter INT
    SET @columnCounter = 0

    DECLARE @columnName VARCHAR(255)
    SET @columnName = 'A'

    WHILE (@columnCounter < 4)
    BEGIN
        IF (@columnCounter == 1)
        BEGIN
            SET @columnName = 'B'
        END
        IF (@columnCounter == 2)
        BEGIN
            SET @columnName = 'C'
        END
        IF (@columnCounter == 3)
        BEGIN
            SET @columnName = 'D'
        END
    END

谢谢你。

4

2 回答 2

2

==. Transact-SQL 使用 simple=进行相等比较,如下所示:

DECLARE @columnCounter INT;
SET @columnCounter = 0;

DECLARE @columnName VARCHAR(255);
SET @columnName = 'Set_To_Value_ID';

WHILE (@columnCounter < 4)
BEGIN
    IF (@columnCounter = 1)
    BEGIN
        SET @columnName = 'Set_To_Variable_ID';
    END
    IF (@columnCounter = 2)
    BEGIN
        SET @columnName = 'Changed_In_SP';
    END
    IF (@columnCounter = 3)
    BEGIN
        SET @columnName = 'Set_To_Comment_Input';
    END
    set @columnCounter += 1;
END
于 2012-11-12T13:38:49.280 回答
1
IF (@columnCounter == 1)

比较应该只是=,==是多种语言的通用语法,但不是 t-sql。

http://msdn.microsoft.com/en-us/library/ms175118(v=sql.100).aspx

于 2012-11-12T13:39:16.547 回答