Stored Procedure Icon dbo.forums_TopicCountForForum

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
@ForumID int 4 INPUT
@MaxDate datetime 8 INPUT
@MinDate datetime 8 INPUT
@UserName nvarchar 100 INPUT
@UnReadTopicsOnly bit 1 INPUT

Total: 5 parameter(s)

SQL

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO




CREATE      PROCEDURE forums_TopicCountForForum
(
	@ForumID int,
	@MaxDate datetime,
	@MinDate datetime,
	@UserName nvarchar(50),
	@UnReadTopicsOnly bit
)
 AS
	IF @UserName IS NULL OR @UnReadTopicsOnly = 0
		SELECT 
			TotalTopics = COUNT(*) 
		FROM 
			Posts 
		WHERE 
			postlevel = 1 AND 
			forumid = @ForumID AND 
			approved = 1 AND
			ThreadDate >= @MinDate AND 
			ThreadDate <= @MaxDate
	ELSE
		SELECT 
			TotalTopics = COUNT(*) 
		FROM 
			Posts P
		WHERE 
			postlevel = 1 AND 
			forumid = @ForumID AND 
			approved = 1 AND
			ThreadDate >= @MinDate AND 
			ThreadDate <= @MaxDate AND
			P.PostID NOT IN (SELECT PostsRead.PostID FROM PostsRead WHERE PostsRead.Username = @UserName) AND
			P.PostId >= (select MarkReadAfter from ForumsRead where username = @UserName and forumid = @ForumID)
	

		












GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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