Stored Procedures [dbo].[Forum_ManageUsers_GetAllByDisplayName]
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_ManageUsers_GetAllByDisplayName]
    @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.vw_Users
        WHERE  DisplayName LIKE @UserNameToMatch
            AND ( PortalId = @PortalId OR (PortalId Is Null AND @PortalId is null ))
        ORDER BY UserName

    SELECT  *
    FROM    dbo.vw_Users u,
            #PageIndexForUsers p
    WHERE  u.UserId = p.UserId
            AND ( PortalId = @PortalId OR (PortalId Is Null AND @PortalId is null ))
            AND p.IndexId >= @PageLowerBound AND p.IndexId <= @PageUpperBound
    ORDER BY u.DisplayName

    SELECT  TotalRecords = COUNT(*)
    FROM    #PageIndexForUsers
END

GO
Uses