Stored Procedures [dbo].[Forum_UserGetAll]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@PortalIdint4
@PageIndexint4
@PageSizeint4
SQL Script


CREATE PROCEDURE dbo.Forum_UserGetAll
    @PortalId int,
    @PageIndex int,
    @PageSize int
AS
    BEGIN
    -- Set the page bounds
        DECLARE @PageLowerBound INT
        DECLARE @PageUpperBound 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(0, 1)
                          NOT NULL,
              UserId int
            )

    -- Insert into our temp table
        INSERT  INTO #PageIndexForUsers ( UserId )
                SELECT DISTINCT
                        ( UserId )
                FROM    dbo.Forum_Users
                WHERE   ( PortalId = @PortalId )

        SELECT  *
        FROM    dbo.Forum_Users FU
                INNER JOIN dbo.Users U ON FU.UserID = U.UserID
                INNER JOIN #PageIndexForUsers P ON U.UserID = P.UserID
        WHERE   u.UserId = p.UserId
                AND ( PortalId = @PortalId )
                AND p.IndexId >= @PageLowerBound
                AND p.IndexId <= @PageUpperBound
        ORDER BY FirstName + ' ' + LastName

        SELECT  TotalRecords = COUNT(*)
        FROM    #PageIndexForUsers

    END

GO
Uses