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 ..
答案 0 :(得分:2)
是
在IF
子句中,您需要设置变量,因此请使用select
或set
,不要直接写@PasswordStatus = 3
写set/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