Stored Procedure Icon dbo.forums_GetForumsByForumGroupId

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
@ForumGroupId int 4 INPUT
@GetAllForums bit 1 INPUT
@UserName nvarchar 100 INPUT

Total: 3 parameter(s)

SQL

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO




CREATE         PROCEDURE forums_GetForumsByForumGroupId
(
	@ForumGroupId int,
	@GetAllForums	bit = 0,
	@UserName nvarchar(50)
	
)
AS

	-- Do we have a username
	IF @UserName IS NOT NULL
	BEGIN
		-- return all of the columns in all of the forums
		IF @GetAllForums = 0
			-- 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
				ForumGroupId = @ForumGroupId
		ELSE
			-- 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 
				ForumGroupId = @ForumGroupId
	

	END
	ELSE
	BEGIN
		-- return all of the columns in all of the forums
		IF @GetAllForums = 0
			-- get JUST the active forums
			SELECT
				ForumID,
				ForumGroupId,
				ParentId,
				Name,
				Description,
				DateCreated,
				DaysToView,
				Moderated,
				TotalPosts,
				TotalTopics = TotalThreads,
				MostRecentPostID,
				MostRecentThreadID,
				MostRecentPostDate,
				MostRecentPostAuthor,
				Active = 1,
				SortOrder,
				IsPrivate = ISNULL((SELECT DISTINCT ForumID FROM PrivateForums WHERE ForumID = F.ForumID), 0),
				DisplayMask
			FROM Forums F (nolock)
			WHERE Active = 1 AND
				ForumGroupId = @ForumGroupId
		ELSE
			-- get all of the forums
			SELECT
				ForumID,
				ForumGroupId,
				ParentId,
				Name,
				Description,
				DateCreated,
				DaysToView,
				Moderated,
				TotalPosts,
				TotalTopics = TotalThreads,
				MostRecentPostID,
				MostRecentThreadID,
				MostRecentPostDate,
				MostRecentPostAuthor,
				Active,
				SortOrder,
				IsPrivate = ISNULL((SELECT DISTINCT ForumID FROM PrivateForums WHERE ForumID = F.ForumID), 0),
				DisplayMask
			FROM Forums F (nolock)
			WHERE 
				ForumGroupId = @ForumGroupId
	
	END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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