aspnet_Membership_FindUsersByName

ALTER  PROCEDURE dbo.aspnet_Membership_FindUsersByName
    
@ApplicationName       NVARCHAR(256),
    
@UserNameToMatch       NVARCHAR(256),
    
@PageIndex             INT,
    
@PageSize              INT
AS
BEGIN
    
DECLARE @ApplicationId UNIQUEIDENTIFIER
    
SELECT  @ApplicationId = NULL
    
SELECT  @ApplicationId = ApplicationId FROM dbo.aspnet_Applications WHERE LOWER(@ApplicationName= LoweredApplicationName
    
IF (@ApplicationId IS NULL)
        
RETURN 0
   
    
-- Set the page bounds
    DECLARE @PageLowerBound INT
    
DECLARE @PageUpperBound INT
    
DECLARE @TotalRecords   INT
    
SET @PageLowerBound = @PageSize * @PageIndex
    
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound

    
-- Create a temp table TO store the select results
    CREATE TABLE #PageIndexForUsers
    (
        IndexId 
int IDENTITY (01NOT NULL,
        UserId 
UNIQUEIDENTIFIER
    )
     
    
/*此条基本一样,就是条件换成用户名而已,不过好象少了判断用户名是否为空.直接插了.
       按用户名排序
*/

    
-- Insert into our temp table
    INSERT INTO #PageIndexForUsers (UserId)
        
SELECT u.UserId
        
FROM   dbo.aspnet_Users u, dbo.aspnet_Membership m
        
WHERE  u.ApplicationId = @ApplicationId AND m.UserId = u.UserId AND u.LoweredUserName LIKE LOWER(@UserNameToMatch)
        
ORDER BY u.UserName


    
SELECT  u.UserName, m.Email, m.PasswordQuestion, m.Comment, m.IsApproved,
            m.CreateDate,
            m.LastLoginDate,
            u.LastActivityDate,
            m.LastPasswordChangedDate,
            u.UserId, m.IsLockedOut,
            m.LastLockoutDate
    
FROM   dbo.aspnet_Membership m, dbo.aspnet_Users u, #PageIndexForUsers p
    
WHERE  u.UserId = p.UserId AND u.UserId = m.UserId AND
           p.IndexId 
>= @PageLowerBound AND p.IndexId <= @PageUpperBound
    
ORDER BY u.UserName

    
SELECT  @TotalRecords = COUNT(*)
    
FROM    #PageIndexForUsers
    
RETURN @TotalRecords  ---后面基本一样
END
原文地址:https://www.cnblogs.com/ruanbl/p/490048.html