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


CREATE PROCEDURE dbo.[Forum_Members_GetByUsername]
    @PortalId INT,
    @UserNameToMatch NVARCHAR(256),
    @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  UserId
                FROM    dbo.Forum_vw_ForumUsers
                WHERE   Username LIKE @UserNameToMatch
                        AND ( PortalId = @PortalId
                              OR ( PortalId IS NULL
                                   AND @PortalId IS NULL
                                 )
                            )
                ORDER BY UserName

        SELECT  U.[UserID],
                [PostCount],
                [EnableDisplayInMemberList],
                [EnableOnlineStatus],
                [EnablePM],
                [PortalID],
                [FirstName],
                [LastName],
                [Email],
                [Username],
                [PostCount],
                ( SELECT    COUNT(UserID)
                  FROM      dbo.Forum_vw_ForumUsers
                ) AS TotalRecords
        FROM    dbo.Forum_vw_ForumUsers U
                INNER JOIN #PageIndexForUsers P ON U.UserID = P.UserID
        WHERE   ( PortalId = @PortalId
                  OR ( PortalId IS NULL
                       AND @PortalId IS NULL
                     )
                )
                AND P.IndexId >= @PageLowerBound
                AND P.IndexId <= @PageUpperBound
        ORDER BY U.UserName
    END

GO
Uses