用户登录存储过程
UserPower为用户的权限,我这里是int类型的。学生为0,老师为1,专家为3,管理员为4。
返回值是用户的状态,只不过状态中的值,有部分是用户的权限值。
代码CREATE proc Proc_UserLogin
@UserName varchar(10),@UserPwd varchar(10),@UserPower int,@ReturnValues int output
as
begin
if @UserPower=0
if exists(select * from Student where Stu_ID=@UserName and Stu_Pwd=@UserPwd)
begin
select @ReturnValues=Stu_Power from Student where Stu_ID=@UserName and Stu_Pwd=@UserPwd
end
else
begin
select @ReturnValues = -1
end
else if @UserPower=1
if exists(select * from Teacher where Tea_ID=@UserName and Tea_Pwd=@UserPwd)
begin
select @ReturnValues=Tea_Power from Teacher where Tea_ID=@UserName and Tea_Pwd=@UserPwd
end
else
begin
select @ReturnValues = -1
end
else if @UserPower=2
if exists(select * from Expert where Exp_ID=@UserName and Exp_Pwd=@UserPwd)
begin
select @ReturnValues=Exp_Power from Expert where Exp_ID=@UserName and Exp_Pwd=@UserPwd
end
else
begin
select @ReturnValues = -1
end
else if @UserPower=3
if exists(select * from Admin where Adm_ID=@UserName and Adm_Pwd=@UserPwd)
begin
select @ReturnValues=Adm_Power from Admin where Adm_ID=@UserName and Adm_Pwd=@UserPwd
end
else
begin
select @ReturnValues = -1
end
else
begin
select @ReturnValues = -1
end
select @ReturnValues
end
declare @uid int
exec Proc_UserLogin 'admin','admin',3,@uid