Stored Procedure Icon dbo.forums_GetAllForums

Stored Procedure Properties

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

Creation Options

Name Value
QUOTED_IDENTIFIER OFF
ANSI_NULLS ON

Parameters

Name DataType Length Type
@GetAllForums bit 1 INPUT
@UserName nvarchar 100 INPUT

Total: 2 parameter(s)

SQL

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



CREATE                  PROCEDURE forums_GetAllForums
(
	@GetAllForums	bit = 0,
	@UserName nvarchar(50)
)
AS
	-- return all of the columns in all of the forums
	IF @GetAllForums = 0

                -- Is a User Specified?
                IF @UserName IS NOT NULL
			-- get JUST the active forums
			SELECT
				ForumID,
				ForumGroupId,
				ParentId,
				Name,
				Description,
				DateCreated,
				DaysToView,
				Moderated,
				TotalPosts,
				TotalTopics = TotalThreads,
				MostRecentPostID,
				MostRecentThreadID,
				MostRecentPostDate,
				MostRecentPostAuthor,
				Active = 1,
				LastUserActivity = (SELECT LastActivity FROM ForumsRead WHERE Username = @UserName AND ForumID = F.ForumID),
				SortOrder,
				IsPrivate = ISNULL((SELECT DISTINCT ForumID FROM PrivateForums WHERE ForumID = F.ForumID), 0),
				DisplayMask
			FROM 
				Forums F (nolock)
			WHERE 
				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))
			ORDER BY
				Name
                ELSE
			-- get JUST the active forums
			SELECT
				ForumID,
				ForumGroupId,
				ParentId,
				Name,
				Description,
				DateCreated,
				DaysToView,
				Moderated,
				TotalPosts,
				TotalTopics = TotalThreads,
				MostRecentPostID,
				MostRecentThreadID,
				MostRecentPostDate,
				MostRecentPostAuthor,
				Active = 1,
				LastUserActivity = NULL,
				SortOrder,
				IsPrivate = 0,
				DisplayMask
			FROM 
				Forums F (nolock)
			WHERE 
				Active = 1 AND
				ForumID NOT IN (SELECT ForumID from PrivateForums)
			ORDER BY
				Name

	ELSE
                -- Is a User Specified?
                IF @UserName IS NOT NULL

			-- get all of the forums
			SELECT
				ForumID,
				ForumGroupId,
				ParentId,
				Name,
				Description,
				DateCreated,
				DaysToView,
				Moderated,
				TotalPosts,
				TotalTopics = TotalThreads,
				MostRecentPostID,
				MostRecentThreadID,
				MostRecentPostDate,
				MostRecentPostAuthor,
				Active,
				LastUserActivity = (SELECT LastActivity FROM ForumsRead WHERE Username = @UserName AND ForumID = F.ForumID),
				SortOrder,
				IsPrivate = ISNULL((SELECT DISTINCT ForumID FROM PrivateForums WHERE ForumID = F.ForumID), 0),
				DisplayMask
			FROM 
				Forums F (nolock)
			WHERE 
				(ForumID NOT IN (SELECT ForumID from PrivateForums) OR
				ForumID IN (SELECT ForumID FROM PrivateForums WHERE RoleName IN (SELECT RoleName from UsersInRoles WHERE username = @UserName)))
			ORDER BY
				Name

                ELSE
			-- get JUST the active forums
			SELECT
				ForumID,
				ForumGroupId,
				ParentId,
				Name,
				Description,
				DateCreated,
				DaysToView,
				Moderated,
				TotalPosts,
				TotalTopics = TotalThreads,
				MostRecentPostID,
				MostRecentThreadID,
				MostRecentPostDate,
				MostRecentPostAuthor,
				Active = 1,
				LastUserActivity = NULL,
				SortOrder,
				IsPrivate = 0,
				DisplayMask
			FROM 
				Forums F (nolock)
			WHERE 
				ForumID NOT IN (SELECT ForumID from PrivateForums)
			ORDER BY
				Name


















GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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