Stored Procedure Icon dbo.forums_GetPrevNextThreadID

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
@PostID int 4 INPUT
@NextThread bit 1 INPUT

Total: 2 parameter(s)

SQL

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE procedure forums_GetPrevNextThreadID (
  @PostID int,
  @NextThread bit
)
AS
BEGIN

DECLARE @CurrentThreadID int
DECLARE @CurrentThreadDate datetime
DECLARE @ForumID int
DECLARE @ThreadID int

SELECT @CurrentThreadID = ThreadID, @CurrentThreadDate = ThreadDate, @ForumID = ForumID FROM Posts WHERE PostID = @PostID


  IF @NextThread = 1
	SELECT TOP 1
		@ThreadID = ThreadID
	FROM
		Posts
	WHERE
		PostLevel = 1 AND
		Approved = 1 AND
		ForumID = @ForumID AND
		ThreadDate < @CurrentThreadDate
  ELSE
	SELECT TOP 1
		@ThreadID = ThreadID
	FROM
		Posts
	WHERE
		PostLevel = 1 AND
		Approved = 1 AND
		ForumID = @ForumID AND
		ThreadDate > @CurrentThreadDate

  IF @ThreadID IS NULL
    SELECT ThreadID = @CurrentThreadID
  ELSE
    SELECT ThreadID = @ThreadID
END




GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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