ALTER proc [dbo].[SP_User_Login]
(
@UserName varchar(20),
@UserPwd varchar(20)
)
as
declare @User_Login_row int --用户登录影响的行数 @UserNam是主键
declare @Leve int---得到用户登录级别 0为管理员 1 超级用户 2 一般用户
begin
set @User_Login_row=(select count(*) from [User] where UserName=@UserName and UserPwd=@UserPwd and [State]=1)
set @Leve=(select Leve from [User] where UserName=@UserName and UserPwd=@UserPwd and [State]=1)
if @User_Login_row=1
update [User] set [LasteLoginTime]=[loginTime], [loginTime]=getdate() where UserName=@UserName --登录成功后更新用户的登录时间
if @User_Login_row=1 ---判断用户是否登录成功
if @Leve=1 --判断用户的级别
select 0,0 --返回0表示登录成功且级别为 管理员
else if @Leve=1
select 0,1 --返回1表示登录成功且级别为 超级用户
else
select 0,2 --返回2表示登录成功且级别为 一般用户
else
select 1 --表示登录失败
end
exec SP_User_Login 'admin','admin' (执行返一个数据表)