Stored Procedure Icon dbo.forums_GetAllForumGroupsForModeration

Stored Procedure Properties

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

Creation Options

Name Value
QUOTED_IDENTIFIER ON
ANSI_NULLS ON

Parameters

Name DataType Length Type
@UserName nvarchar 100 INPUT

Total: 1 parameter(s)

SQL

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE            PROCEDURE forums_GetAllForumGroupsForModeration
(
	@UserName nvarchar(50)
)
AS

IF (0 = (SELECT ForumID FROM Moderators WHERE Username = @UserName))

	-- Note, we still only allow the user to moderate forums that he/she has access to
	SELECT 
		ForumGroupId,
		Name,
		SortOrder
	FROM
		ForumGroups
	WHERE
		EXISTS(
			SELECT
				ForumID
			FROM
				FORUMS
			WHERE
				ForumGroups.ForumGroupID = Forums.ForumGroupId AND
				Forums.Active = 1 AND
				(ForumID NOT IN (SELECT ForumID from PrivateForums) OR
				ForumID IN (SELECT ForumID FROM PrivateForums WHERE RoleName IN (SELECT RoleName from UsersInRoles WHERE username = @UserName))) AND
				(SELECT COUNT(*) FROM Posts P (nolock) WHERE P.ForumID = Forums.ForumID and P.Approved = 0) > 0

		)
ELSE
	-- Note, we still only allow the user to moderate forums that he/she has access to
	SELECT 
		ForumGroupId,
		Name,
		SortOrder
	FROM
		ForumGroups
	WHERE
		EXISTS(
			SELECT
				ForumID
			FROM
				FORUMS
			WHERE
				ForumGroups.ForumGroupID = Forums.ForumGroupId AND
				Forums.Active = 1 AND
				(ForumID NOT IN (SELECT ForumID from PrivateForums) OR
				ForumID IN (SELECT ForumID FROM PrivateForums WHERE RoleName IN (SELECT RoleName from UsersInRoles WHERE username = @UserName))) AND
				ForumID IN (SELECT ForumID FROM Moderators WHERE Username = @UserName)  AND
				(SELECT COUNT(*) FROM Posts P (nolock) WHERE P.ForumID = Forums.ForumID and P.Approved = 0) > 0

		)







GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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