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)
 Tree structures and recursive stored procedures

Author  Topic 

nmg196
Yak Posting Veteran

70 Posts

Posted - 2001-02-15 : 19:40:38
Hi,

I've got a problem that's been really annoying me for a while now. My SQL is just good enough for me to do what I need to do...

Basically, my website has a tree structure of categories which has the tree 'drawn' on the left hand side of the page. When a user clicks on a category, it expands revealing it's subcategories. I only want to show one folder open at once, but I do need to be able to go down to about 3 levels. So in the diagram below, the Programming folder has been expanded and the emboldend items will have open folder icons:

Peripherals
Software
___Accounting
___Games
___Programming
______Compilers
______IDEs
______Debuggers
___Operating Systems
___Word Processors
Computers
Services

The question is is there a way I call call a stored procedure that will a return all the information I need to draw the above structure?

I'm guessing that I'll need to know the id, parent id and level of each item in the list.

I'm storing the information in a table as below (where a parentID of 0 signifies a root node):

ParentID ID strName
0 1 Peripherals
0 2 Software
0 3 Computers
0 4 Services
2 5 Accounting
2 6 Games
2 7 Programming
2 8 Operating Systems
2 9 Word Processors
7 10 Compilers
7 11 IDEs
7 12 Debuggers
... etc

This should be really easy, but I can't work out how to get all the information back in one query.

Thanks!

Nick...

Edited by - nmg196 on 02/15/2001 19:44:31
   

- Advertisement -