Tuesday, January 10, 2023

Stored Procedure with Paging SQL by Microsoft

 ALTER PROCEDURE [dbo].[aspnet_Membership_GetAllUsers]

    @ApplicationName       nvarchar(256),

    @PageIndex             int,

    @PageSize              int

AS

BEGIN


 DECLARE @PageLowerBound int

    DECLARE @PageUpperBound int

    DECLARE @TotalRecords   int

    SET @PageLowerBound = @PageSize * @PageIndex

    SET @PageUpperBound = @PageSize - 1 + @PageLowerBound


 SELECT @TotalRecords = @@ROWCOUNT


    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

    RETURN @TotalRecords

END

No comments:

Post a Comment