我要存储过程中,根据用户名和密码,查出用户USERID,然后在存储过程中执行其他关于USERID的语句
我用
select top 1 pe_pwdd,pe_sex,pe_nini,diqu1,@UserId=UserId
from dbo.[useruser1]
where pe_email=@UserName and pe_pwdd=@paww
提示错误,查询和赋值要分开
我该怎么办呢?难道一定要先 if exists(select....where....),然后再 if exists(select..,@UserId=UserId..where....)吗。(用select top 1..,@UserId=UserId..where....也不行,提示错误))这样的话不等于又做了一次重复的SELECT查询吗,有没有简单的好办法,
因为我一次要查询很多字段内容,在存储过程中我要知道UserId的值,因为后面要紧跟着update set where UserId=取出的UserId值。
我用
select top 1 pe_pwdd,pe_sex,pe_nini,diqu1,@UserId=UserId
from dbo.[useruser1]
where pe_email=@UserName and pe_pwdd=@paww
提示错误,查询和赋值要分开
我该怎么办呢?难道一定要先 if exists(select....where....),然后再 if exists(select..,@UserId=UserId..where....)吗。(用select top 1..,@UserId=UserId..where....也不行,提示错误))这样的话不等于又做了一次重复的SELECT查询吗,有没有简单的好办法,
因为我一次要查询很多字段内容,在存储过程中我要知道UserId的值,因为后面要紧跟着update set where UserId=取出的UserId值。
select top 1 @pe_pwdd = pe_pwdd,@pe_sex=pe_sex,@pe_nini=pe_nini,@diqu1 = diqu1,@UserId=UserId
from dbo.[useruser1]
where pe_email=@UserName and pe_pwdd=@paww
--查询和赋值不能在一个语句里执行的
--写成两段
--这个结果集给asp用
select top 1 pe_pwdd,pe_sex,pe_nini,diqu1 from dbo.[useruser1]
where pe_email=@UserName and pe_pwdd=@paww--这个自己内部处理
select top 1 UserId=UserId
from dbo.[useruser1]
where pe_email=@UserName and pe_pwdd=@paww