
[dbo].[Forum_ManageUsers_GetAllByDisplayName]
CREATE PROCEDURE dbo.[Forum_ManageUsers_GetAllByDisplayName]
@PortalId int,
@UserNameToMatch nvarchar(256),
@PageIndex int,
@PageSize int
AS
BEGIN
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
CREATE TABLE #PageIndexForUsers
(
IndexId int IDENTITY (0, 1) NOT NULL,
UserId int
)
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