
[dbo].[Forum_Post_Reported_GetUsers]
CREATE PROCEDURE dbo.Forum_Post_Reported_GetUsers
@PortalId INT,
@PageIndex INT,
@PageSize INT
AS
BEGIN
DECLARE @PageLowerBound INT
DECLARE @PageUpperBound INT
SET @PageLowerBound = @PageSize * @PageIndex
SET @PageUpperBound = @PageSize - 1 + @PageLowerBound
CREATE TABLE #PagePostIndex
(
IndexId INT IDENTITY(0, 1)
NOT NULL,
UserID INT
)
INSERT INTO #PagePostIndex ( U.UserID )
SELECT DISTINCT
( U.UserID )
FROM dbo.Forum_Posts P
INNER JOIN dbo.Forum_Users U ON P.UserID = U.UserID
WHERE ( PortalId = @PortalId )
AND PostReported > 0
AND Addressed < PostReported
SELECT UserID,
( SELECT COUNT(UserID)
FROM dbo.Forum_Posts P
WHERE UserID = P.UserID
) AS ReportedPostCount,
( SELECT COUNT(UserID)
FROM dbo.Forum_Posts P
WHERE UserID = P.UserID
AND PostReported > 0
AND Addressed < PostReported
) AS UnaddressedPostCount
FROM #PagePostIndex
WHERE IndexId >= @PageLowerBound
AND IndexId <= @PageUpperBound
SELECT TotalRecords = COUNT(*)
FROM #PagePostIndex
END
GO