Stored Procedure Icon dbo.forums_GetModeratedPosts

Stored Procedure Properties

Name Value
Owner dbo
Created 2004-05-31
Startup False
Encrypted False

Creation Options

Name Value
QUOTED_IDENTIFIER OFF
ANSI_NULLS OFF

Parameters

Name DataType Length Type
@UserName nvarchar 100 INPUT

Total: 1 parameter(s)

SQL

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO




CREATE      PROCEDURE forums_GetModeratedPosts
(
	@UserName nvarchar(50)
)
 AS
	-- returns a list of posts awaiting moderation
	-- the posts returned are those that this user can work on
	-- if Moderators.ForumID = 0 for this user, then they can moderate ALL forums
	IF EXISTS(SELECT NULL FROM Moderators (nolock) WHERE UserName=@UserName AND ForumID=0)
		-- return ALL posts awaiting moderation
		SELECT
			PostID,
			ThreadID,
			ThreadDate,
			PostLevel,
			P.SortOrder,
			P.ParentID,
			Subject,
			Approved,
			P.ForumID,
			ForumName = F.Name,
			PostDate,
			P.UserName,
			Replies = 0,
			Body,
			TotalViews,
			IsLocked,
			HasRead = 1
		FROM Posts P (nolock)
			INNER JOIN Forums F (nolock) ON
				F.ForumID = P.ForumID
		WHERE Approved = 0
		ORDER BY P.ForumID, PostDate
	ELSE
		-- return only those posts in the forum this user can moderate
		SELECT
			PostID,
			P.ParentID,
			Approved,
			ThreadID,
			ThreadDate,
			PostLevel,
			P.SortOrder,
			Subject,
			P.ForumID,
			ForumName = F.Name,
			PostDate,
			Replies = 0,
			P.UserName,
			Body,
			TotalViews,
			IsLocked,
			HasRead = 1
		FROM Posts P (nolock)
			INNER JOIN Forums F (nolock) ON
				F.ForumID = P.ForumID
		WHERE 
			Approved = 0 AND 
			P.ForumID IN (SELECT ForumID FROM Moderators (nolock) WHERE UserName=@UserName)
		ORDER BY P.ForumID, PostDate



















GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

Generated on 26/08/2004 15:05:29 by DataAide.