Stored Procedure Icon dbo.forums_MarkAllThreadsRead

Stored Procedure Properties

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

Creation Options

Name Value
QUOTED_IDENTIFIER OFF
ANSI_NULLS OFF

Parameters

Name DataType Length Type
@ForumID int 4 INPUT
@UserName nvarchar 100 INPUT

Total: 2 parameter(s)

SQL

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO




CREATE       PROCEDURE forums_MarkAllThreadsRead
(
	@ForumID int,
	@UserName nvarchar (50)
)
 AS
BEGIN
	DECLARE @PostID int

	-- first find the max post id for the given forum
	SELECT @PostID = MAX(PostID) FROM Posts WHERE ForumID = @ForumID

	-- Do we need to performa an INSERT or an UPDATE?
	IF EXISTS (SELECT ForumID FROM ForumsRead WHERE ForumID = @ForumID AND Username = @UserName)
		UPDATE 
			ForumsRead
		SET
			MarkReadAfter = @PostID
		WHERE
			ForumID = @ForumID AND
			Username = @UserName
	ELSE
		INSERT INTO
			ForumsRead
			(ForumId, Username, MarkReadAfter)
		VALUES
			(@ForumID, @UserName, @PostID)

	-- Do some clean up
	DELETE PostsRead WHERE PostID < @PostID AND Username = @UserName

END
		

















GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


					

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