我有两张这样的表
usertable RoleTable
----------------------- ---------------------------
UserID|UserName|Pwd|RoleID RoleID|RoleName
1 |Anil |123|1 1 |Admin
我必须在用户名和密码匹配时获得rolename
,是否可以为我提供存储过程?
答案 0 :(得分:1)
您的方案可能存在一些问题:
假设你知道这些警告:
CREATE PROCEDURE GetRoleName
@UserName VARCHAR(50), -- NVARCHAR if needed
@Password VARCHAR(50)
AS
SELECT R.RoleName FROM [User] U
INNER JOIN [Role] R ON R.RoleId = U.RoleId
WHERE U.UserName = @UserName and U.Pwd = @Password;
GO
答案 1 :(得分:0)
尝试以下查询:
SELECT role.RoleName FROM usertable user JOIN RoleTabel role WHERE user.UserName=user_name AND user.Pwd=password;
您可以通过以下方式在存储过程中实现上述查询
CREATE PROCEDURE proc_GetRoleName
@username nvarchar(50),
@password nvarchar(50)
AS
BEGIN
SELECT role.RoleName FROM usertable user JOIN RoleTabel role WHERE user.UserName=@username AND user.Pwd=@password ;
END