这是语法错误吗?

时间:2012-07-26 06:51:05

标签: sql sql-server sql-server-2005

IF( @ActiveStatus = 1 )
BEGIN 
    @PasswordStatus = 3 
END
ELSE 
    SET @PasswordStatus = (SELECT password_status 
                             FROM tbl_user
                            WHERE login_name = @LoginName_fromApp
                              AND password=@Pass
                           )

我正在使用Microsoft SQL Server Management Studio ..

3 个答案:

答案 0 :(得分:2)

IF子句中,您需要设置变量,因此请使用selectset,不要直接写@PasswordStatus = 3set/select @PasswordStatus = 3

尝试

if( @ActiveStatus = 1 ) 
begin 
--chage of code 

 set @PasswordStatus = 3 --or select @PasswordStatus = 3
   END
else 
begin
Set @PasswordStatus = (select password_status from tbl_user where  login_name=@LoginName_fromApp and password=@Pass)

end

修改

评论 - @ marc_s 如果您只是设置“标量”值,请使用SET @Var = 3 - 如果您实际选择的话,请使用SELECT @Var = ID FROM dbo.Table1表(或视图)

答案 1 :(得分:0)

当您将评估者设置为任何变量时,请使用设置,如下所示

if( @ActiveStatus = 1 )
begin
Set @PasswordStatus = 3 
END
else 
begin
Set @PasswordStatus = (select password_status from tbl_user where
login_name=@LoginName_fromApp and password=@Pass)
end
Select @PasswordStatus 

答案 2 :(得分:0)

另一个

select 
        @PasswordStatus = case when @ActiveStatus = 1 then 3 else password_status  end
from 
    tbl_user  
where  
        login_name = @LoginName_fromApp and password=@Pass