如何从多个表创建基于roleid的登录过程 [英] How to create login procedure based on roleid from multiple table

查看:116
本文介绍了如何从多个表创建基于roleid的登录过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何根据多个表格中的roleid创建登录程序



我有两张桌子陪着我

table-1 tblTeacher

-------------------------------------------- --------

Id名称电子邮件密码RoleId状态

-------------------- --------------------------------

1 aaa aaaa 123 1 0

2 bbb bbbb 1234 2 1

3 ccc cccc 1234 1 1



table-2 tblStudent

------------------------------------------------ ----

Id名称电子邮件密码RoleId状态

------------------------ ----------------------------

1 xxx xxxx 123 3 1

2 yyy yyyy 1234 3 0





i想根据角色ID登录,如果状态为真(1)



W帽子我试过:



how to create login procedure based on roleid from multiple table

I have two table with me
table-1 tblTeacher
----------------------------------------------------
Id Name Email Password RoleId Status
----------------------------------------------------
1 aaa aaaa 123 1 0
2 bbb bbbb 1234 2 1
3 ccc cccc 1234 1 1

table-2 tblStudent
----------------------------------------------------
Id Name Email Password RoleId Status
----------------------------------------------------
1 xxx xxxx 123 3 1
2 yyy yyyy 1234 3 0


i want to login based on the role id and if status is true(1)

What I have tried:

create procedure spLoginn(
@Email varchar(50),
@Pasword varchar(20),
@RId int out
)
as begin
  --declare @Rid int
  if @Email is not null
     if @Pasword is not null
	   set @Rid=(Select RoleId from tblTeacher where Email=@Email and Pasword=@Pasword)
	 if @Rid=0
	   set @Rid=(Select RoleId from tblStudent where Email=@Email and Pasword=@Pasword)
	   end

推荐答案

试试



try

alter procedure spLoginn(
@Email varchar(50),
@Pasword varchar(20),
@RId int out
)
as BEGIN

  
  if ( @Email is not null and  @Pasword is not null ) 
		begin
			   set @Rid=(Select RoleId from tblTeacher where Email=@Email and Pasword=@Pasword)
			 if @Rid is null
			   set @Rid=(Select RoleId from tblStudent where Email=@Email and Pasword=@Pasword)
	     end
  END





如果 @RId null 然后表格中没有电子邮件/密码组合。



if @RId is null then the Email/Password combination is not present either table.


这篇关于如何从多个表创建基于roleid的登录过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆