我这个存储过程对吗?

sizheng0320 2003-08-19 09:44:07
有个test表,有用户名和密码。
存储过程的功能是:该存储过程的作用是验证用户密码。返回值:当用户名和密码一致,返回0;当用户名和密码不一致,返回1;当用户名不存在时,返回-1

我是这样写的:

create procedure test
@username char(8),
@pwd char(10),
@result int out
as
declare @cnt int
select @cnt=count(用户名) from userinfo where 用户名=@username
if @cnt=0
return -1
else
begin
select @cnt=count(用户名) from userinfo where 用户名=@username and 用户密码=@pwd
if @cnt<>0
return 0
else
return 1
end

然后执行下面的语句:

declare @result int
exec test 'test','test',@result output
select @result

结果返回NULL。
哪里有问题?
...全文
20 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sizheng0320 2003-08-19
  • 打赏
  • 举报
回复
谢谢!
pengdali 2003-08-19
  • 打赏
  • 举报
回复
create procedure test
@username varchar(8),
@pwd varchar(10),
@result int out
as
declare @cnt int
select @cnt=count(用户名) from userinfo where 用户名=@username
if @cnt=0
set @result=-1
else
begin
select @cnt=count(用户名) from userinfo where 用户名=@username and 用户密码=@pwd
if @cnt<>0
set @result=0
else
set @result=1
end

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧