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)
 Classic Tree-in-a-table question with a small twist

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-03-14 : 09:11:35
Mickey writes "I have a table containing a tree-structure. The table is like this:

ID (int ID)
Name (nvarchar[100])
Parent (int)
Sortorder (tinyint)

Sampledata could be:
1, 'root', null, 0
2, 'menu 1', 1, 0
3, 'menu 2', 1, 1
4, 'menu 1-1', 2, 0
5, 'menu 2-1', 3, 0
6, 'menu 1-1-1', 4, 0
7, 'menu 1-2', 2, 1
8, 'menu 1-3', 2, 2

Now I want a stored procedure to return these menuitems in the order they should be written in a tree. So with the above sampledata the correct order (based on the parent and sortorder columns) would be: 1,2,4,6,7,8,3,5

How would I make an optimized stored procedure to perform this task?"
   

- Advertisement -