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)
 count records in a nested select

Author  Topic 

mcsleazycrisps
Starting Member

1 Post

Posted - 2004-08-17 : 10:34:54
I'm currently developing a forum system and trying to get the page to display the number of posts under a topic, and if there's any file "attachments" to the post the data is stored like this:

[TABLE NAME: site_forum_thread]
forum_threadid (id)
motherid ( the parent topic - 0 if it's a "top-level" post)
forumid (what forum it belongs to)
title
txt
filename ( filename if there's a file attached, otherwise NULL)
pubdate
author (int field referring to the id in a user's table)

To display a list of all the topics in the forum it pulls all the records with a motherid of 0 and it's author (using a join).

select site_forum_thread.*, site_reg.username, site_reg.regid from site_forum_thread LEFT JOIN site_reg on site_forum_thread.author = site_reg.regid where forumid = @forumid AND motherid = 0

What i need it to do is to count the number of children under the motherid and the number of filenames. I'm using stored procedures... any ideas on how to do this? I've tried using a nested select but it keeps returning 0 - unless i'm doing something wrong.

Thanks!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-17 : 10:52:49
well, you can check this out for more details on designing trees:
http://www.sqlteam.com/item.asp?ItemID=8866

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-08-17 : 11:39:15
Ohhh!!! I want to through mine out there too:

http://www.seventhnight.com/treestructs.asp

Corey
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-08-17 : 11:46:19
corey what is this, the second time we did that?? next time i'll post yours and you do the one on sqlteam, just for the fun of it :)))

Go with the flow & have fun! Else fight the flow :)
Go to Top of Page

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2004-08-17 : 11:56:10
k

Corey
Go to Top of Page
   

- Advertisement -