Stored Procedure Icon dbo.forums_GetAllForumsByForumGroupId

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

Total: 2 parameter(s)

SQL

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE        PROCEDURE forums_GetAllForumsByForumGroupId
(
	@ForumGroupId int,
	@GetAllForums	bit = 0
	
)
AS
	-- return all of the columns in all of the forums
	IF @GetAllForums = 0
		-- get JUST the active forums
		SELECT
			ForumID,
			ForumGroupId,
			Name,
			Description,
			DateCreated,
			DaysToView,
			Moderated,
			TotalPosts = (SELECT COUNT(*) FROM Posts P (nolock) WHERE P.ForumID = F.ForumID AND P.Approved=1),
			TotalTopics = (SELECT COUNT(*) FROM Posts P2 (nolock) WHERE P2.ForumID = F.ForumID AND P2.Approved=1 AND P2.PostLevel=1),
			MostRecentPostID = (SELECT TOP 1 PostID FROM Posts P3 (nolock) WHERE P3.ForumID = F.ForumID AND P3.Approved=1 AND PostDate < GetDate() ORDER BY PostDate DESC),
			MostRecentPostDate = (SELECT TOP 1 PostDate FROM Posts P3 (nolock) WHERE P3.ForumID = F.ForumID AND P3.Approved=1 AND PostDate < GetDate() ORDER BY PostDate DESC),
			MostRecentPostAuthor = (SELECT TOP 1 Username FROM Posts P3 (nolock) WHERE P3.ForumID = F.ForumID AND P3.Approved=1 AND PostDate < GetDate() ORDER BY PostDate DESC),
			Active = 1,
			SortOrder
		FROM Forums F (nolock)
		WHERE Active = 1 AND
			ForumGroupId = @ForumGroupId
	ELSE
		-- get all of the forums
		SELECT
			ForumID,
			ForumGroupId,
			Name,
			Description,
			DateCreated,
			DaysToView,
			Moderated,
			TotalPosts = (SELECT COUNT(*) FROM Posts P (nolock) WHERE P.ForumID = F.ForumID AND P.Approved=1),
			TotalTopics = (SELECT COUNT(*) FROM Posts P2 (nolock) WHERE P2.ForumID = F.ForumID AND P2.Approved=1 AND P2.PostLevel=1),
			MostRecentPostID = (SELECT TOP 1 PostID FROM Posts P3 (nolock) WHERE P3.ForumID = F.ForumID AND P3.Approved=1 AND PostDate < GetDate() ORDER BY PostDate DESC),
			MostRecentPostDate = (SELECT TOP 1 PostDate FROM Posts P3 (nolock) WHERE P3.ForumID = F.ForumID AND P3.Approved=1 AND PostDate < GetDate() ORDER BY PostDate DESC),
			MostRecentPostAuthor = (SELECT TOP 1 Username FROM Posts P3 (nolock) WHERE P3.ForumID = F.ForumID AND P3.Approved=1 AND PostDate < GetDate() ORDER BY PostDate DESC),
			Active,
			SortOrder
		FROM Forums F (nolock)
		WHERE 
			ForumGroupId = @ForumGroupId




















GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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