ALTER PROCEDURE dbo.aspnet_UsersInRoles_GetUsersInRoles --查询某角色的用户
@ApplicationName NVARCHAR(256),
@RoleName NVARCHAR(256)
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN(1)
/*返回@ApplicationId,不存在返回1*/
DECLARE @RoleId UNIQUEIDENTIFIER
SELECT @RoleId = NULL
SELECT @RoleId = RoleId
FROM dbo.aspnet_Roles
WHERE LOWER(@RoleName) = LoweredRoleName AND ApplicationId = @ApplicationId
/*查询此用户的角色ID*/
IF (@RoleId IS NULL)
RETURN(1)
SELECT u.UserName
FROM dbo.aspnet_Users u, dbo.aspnet_UsersInRoles ur
WHERE u.UserId = ur.UserId AND @RoleId = ur.RoleId AND u.ApplicationId = @ApplicationId
ORDER BY u.UserName
RETURN(0)
/*查询此角色的全部用户*/
END
@ApplicationName NVARCHAR(256),
@RoleName NVARCHAR(256)
AS
BEGIN
DECLARE @ApplicationId UNIQUEIDENTIFIER
SELECT @ApplicationId = NULL
SELECT @ApplicationId = ApplicationId FROM aspnet_Applications WHERE LOWER(@ApplicationName) = LoweredApplicationName
IF (@ApplicationId IS NULL)
RETURN(1)
/*返回@ApplicationId,不存在返回1*/
DECLARE @RoleId UNIQUEIDENTIFIER
SELECT @RoleId = NULL
SELECT @RoleId = RoleId
FROM dbo.aspnet_Roles
WHERE LOWER(@RoleName) = LoweredRoleName AND ApplicationId = @ApplicationId
/*查询此用户的角色ID*/
IF (@RoleId IS NULL)
RETURN(1)
SELECT u.UserName
FROM dbo.aspnet_Users u, dbo.aspnet_UsersInRoles ur
WHERE u.UserId = ur.UserId AND @RoleId = ur.RoleId AND u.ApplicationId = @ApplicationId
ORDER BY u.UserName
RETURN(0)
/*查询此角色的全部用户*/
END