请高手帮我编写一个存储过程实现判断用户登陆信息:
数据表 admin_info(username,password,id)
设计存储过程实现正确返回1,错误返回0,密码错误返回2,用户不存在返回3proceduce(uname varchar,pword varchar,info int)谢谢。
数据表 admin_info(username,password,id)
设计存储过程实现正确返回1,错误返回0,密码错误返回2,用户不存在返回3proceduce(uname varchar,pword varchar,info int)谢谢。
create proc wsp
@uname varchar(50),
@pword varchar(50),
@info int output
as
if exists(select 1 from admin_info where uname=@uname)--用户存在
begin
if exists(select 1 from admin_info where uname=@uname and pword=@pword) --用户和密码正确
set @info=1
else --用户存在。密码不正确
set @info=2
end
else --用户不存在
set @info=3
数据表 admin_info(username,password,id)
设计存储过程实现正确返回1,错误返回0,密码错误返回2,用户不存在返回3 create proc test
@uname varchar(100),
@pword varchar(16),
@info int
as
begin
if (isnull(@uname,'') = '') or isnull(@pword ,'') = '') or isnull(@info ,'') = '') return 0
if exists(select 1 from admin_info where username = @uname)
if exists(select 1 from admin_info where username = @uname and password = @pword)
return 1
else
return 2
else
return 3
end
@uname varchar(100),
@pword varchar(16),
@info int output
as
begin
declare @pwd varchar(16)
select @pwd = password from admin_info where username = @uname
if @@rowcount=0
set @info = 3 -- 用户不存在
else
set @info = case when @pwd=@pword
then 1 -- 用户和密码正确
else 2 end -- 用户存在,密码不正确
return @info
end
create proc test
@uname varchar(100),
@pword varchar(16),
@info int
as
begin
if (isnull(@uname,'') = '') or isnull(@pword ,'') = '') or isnull(@info ,'') = '') return 0
if exists(select 1 from admin_info where username = @uname)
if exists(select 1 from admin_info where username = @uname and password = @pword)
return 1
else
return 2
else
return 3
end
@uname varchar(50),
@pword varchar(50),
@info int output
as
if exists(select 1 from admin_info where uname=@uname)--用户存在
begin
if exists(select 1 from admin_info where uname=@uname and pword=@pword) --用户和密码正确
set @info=1
else --用户存在。密码不正确
set @info=2
end
else --用户不存在
set @info=3
@userid int,
@password varchar(15),
@isLogin int output
as
begin
declare @count int,
@imd int
select @count=count(userId) from admin_user where userid=@userid
if @count=0
set @isLogin=2 --用户名不存在
else
begin
select @imd=COUNT(userId) from admin_user where userid=@userid and password=@password
if @imd=1
set @isLogin=1--登录成功
else
set @isLogin=0--密码错误
end
end