ALTER PROCEDURE dbo.aspnet_UsersInRoles_FindUsersInRole --查询某角色中的所有用户
@ApplicationName NVARCHAR(256),
@RoleName NVARCHAR(256),
@UserNameToMatch 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
/*查询此角色是否存在*/
IF (@RoleId IS NULL) --不存在则返回1
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 AND LoweredUserName LIKE LOWER(@UserNameToMatch)
ORDER BY u.UserName
/*查询此角色中的用户,返回0*/
RETURN(0)
END
@ApplicationName NVARCHAR(256),
@RoleName NVARCHAR(256),
@UserNameToMatch 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
/*查询此角色是否存在*/
IF (@RoleId IS NULL) --不存在则返回1
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 AND LoweredUserName LIKE LOWER(@UserNameToMatch)
ORDER BY u.UserName
/*查询此角色中的用户,返回0*/
RETURN(0)
END