Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 BTW.. Graz, perhaps a mistake here?

Author  Topic 

Carlos
Starting Member

6 Posts

Posted - 2001-02-03 : 20:44:32
Hi Graz

I've been reading -well, studying!- your SQL for Threaded Discussion Forums code, and I think you missed something... or I am understing one of the steps.

To avoid pasting the same code you can find in the article, I'll tell you that the supposed mistake is, in the spPost sproc, when you're replying to a previous post, and you're doing it in the middle of a thread, you do these:
1)First, find if there are post at the same level or higher:
IF EXISTS (SELECT * FROM Posts WHERE PostLevel <=
ParentLevel AND SortOrder > @ParentSortOrder)

2)Find the next post at the same level or higher:
SELECT @NextSortOrder = Min(SortOrder)
FROM Posts
WHERE PostLevel <= @ParentLevel
AND SortOrder > @ParentSortOrder

3)Move the existing posts down.(UPDATE Posts ... )

OK, in step 2, why didn't you add (AND ThreadID = @ThreadID) to the WHERE clause? It seems to me you're searching all of the posts, not only those that belong to the current thread.

That's it, tell me I am wrong. :-)

Carlos

lundrigan
Starting Member

1 Post

Posted - 2003-01-28 : 12:17:18
I was reviewing your code and I have a simple question. Why not order by threadid and postdate, wouldn't that remove the need to resort the sortorder as new message come in? Or is there something there that I am missing?


quote:

I'd agree with you. I fixed the code and reposted. Thanks for proof reading. You were the first out of 3500+ to catch it. Keep those eagle eyes reading :)

SQLTeam.com



Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2003-01-28 : 12:49:29
Assume the following posts, all in thread id #1


Post 1 (Monday)
Reply 1 (Tuesday)
Reply 2 (Wednesday)



Now assume that someone replies to "Reply 1" on Thursday. I want the structure to appear as follows:


Post 1 (Monday)
Reply 1 (Tuesday)
Reply 3 (Thursday)
Reply 2 (Wednesday)





If I simply sort by date within thread, "Reply 3" will appear at the end of the list.



===============================================
Creating tomorrow's legacy systems today.
One crisis at a time.
Go to Top of Page
   

- Advertisement -