嗯,显然这不起作用。我得到“错误的语法'=''错误。 是否可以在存储过程中多次更改变量的值?
与此示例类似:
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
谢谢。
答案 0 :(得分:2)
是==
。 Transact-SQL使用简单的=
进行相等性比较,如下所示:
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
答案 1 :(得分:1)
IF (@columnCounter == 1)
比较应该是=
,==
是许多语言中的常用语法,但不是t-sql。
http://msdn.microsoft.com/en-us/library/ms175118(v=sql.100).aspx