2
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..

4

3 回答 3

2

是的

IF子句中你需要设置变量所以使用selector set,不要写直接@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

于 2012-07-26T06:52:20.563 回答
0

另一个

select 
        @PasswordStatus = case when @ActiveStatus = 1 then 3 else password_status  end
from 
    tbl_user  
where  
        login_name = @LoginName_fromApp and password=@Pass
于 2012-07-26T08:13:15.923 回答
0

当您将 valuer 设置为任何变量时,请使用Set如下

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 
于 2012-07-26T06:55:12.293 回答