我有一个Users
包含以下列的表格:
Userid Username Password
1 Username1 Password1
2 Username2 Password2
3 Username3 Password3
还有一张桌子,MappingRoles
:
Userid RoleId
1 1 (FinanceUser)
1 2 (Agent)
1 3 (Client)
我想编写一个应该返回两列的存储过程
IsValidUser
Roles -- of the user
这是我的尝试:
CREATE PROCEDURE getRoles
@Username varchar(50),
@Password varchar(50)
AS
BEGIN
Select * from Users as x inner join MappingRoles as y
on x.Userid=y.Userid
where x.Userid=(Select Userid from Users
where UserName='Username1' and Password='Password1');
END
GO
我期望在此查询中进行优化以提供 2 个返回值:
IsUserAuthenticated
- (内部Select
来自Users
)如果它存在,那么所有的值。
任何建议将不胜感激。