sql存储过程子查询错误

时间:2014-03-19 17:54:41

标签: sql

我正在尝试使用OUTPUT参数为用户登录编写存储过程,但是我收到以下错误:

Msg 207, Level 16, State 1, Procedure userLogin_proc9, Line 7
Invalid column name 'count'.
Msg 116, Level 16, State 1, Procedure userLogin_proc9, Line 7
Only one expression can be specified in the select list when the subquery 
 is not introduced with EXISTS

存储过程:

create procedure userLogin_proc
@userName nvarchar(45),
@passCode nvarchar(20),
@userID int OUTPUT
as
begin 
if(select count userName,passCode from userLogin where userName=@userName 
and passCode =     @passCode) = 0
set @userID =0 
end

如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

尝试count(*)而不是count userName,passCode

答案 1 :(得分:1)

您可以将IF语句更改为

IF NOT EXISTS(SELECT userName FROM userLogin WHERE userName=@userName AND passCode = @passCode)
    SET @userID = 0