I have a stored procedure to add a topic from an SQL Server stored procedure:
CREATE PROCEDURE DS_NewTopic
@Forum_ID int, @Subject varchar(64), @Message varchar(4096)
AS
DECLARE @NewTopicID int
DECLARE @NewThreadID int
DECLARE @Author_ID int
-- Set new topic author ID to match for 'testuser':
SET @Author_ID = 15
-- Add new topic and retrieve Topic ID:
INSERT tblTopic (Forum_ID, Subject, Priority) VALUES (@Forum_ID, @Subject, 0)
SET @NewTopicID = (SELECT MAX(Topic_ID) FROM tblTopic)
-- Add thread and retrieve Thread ID:
INSERT tblThread (Topic_ID, Author_ID, Message) VALUES (@NewTopicID, @Author_ID, @Message)
SET @NewThreadID = (SELECT MAX(Thread_ID) FROM tblThread)
-- Update Thread ID's in tblTopic
UPDATE tblTopic SET Start_Thread_ID = @NewThreadID, Last_Thread_ID = @NewThreadID WHERE Topic_ID = @NewTopicID
GO
This works reasonably well apart from:
1) The post is never shown as the 'Last Post'
2) If the post is the only one in a forum the post count stays at zero.
How can I modify the above SP to have the topic added 'correctly'?
Thanks