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
 Transact-SQL (2000)
 Populate menu tree and SQL joins

Author  Topic 

Andal
Starting Member

1 Post

Posted - 2003-01-30 : 10:45:21
Hi. Can somebody help me with menu tree query?

The table structure is (menu_id, parent_id, title)

To populate menu tree i use the following query:

select
m1.title as m1_title, m2.title as m2_title, m3.title as m3_title
from menu m1, menu m2, menu m3
where m3.parent_id=*m2.menu_id and m2.parent_id=m1.menu_id

I need to get all menu tree (for example just 3 levels as in my query)

It is no problem with 2 level menu , but how it will be with more levels (3 or 4)

The main problem of query above is:
If upper menu level just call it (level1) had no child objects (level2 and level3) the row does not apear in the recordset

i need to get the following result, if upper level have no child objects:
level1->Null-->Null
level1->level2-->Null
level1->level2-->level3

with the sqlqyery above it is possible to show only the followings:
level1->level2-->Null
level1->level2-->level3
If the tree node like this: level1->Null-->Null the record a not selected.

Can you provide any suggestion?

I 'll be happy to get any advice from you.
And sorry for my english.
Thanks



Edited by - andal on 01/30/2003 10:46:54

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-01-30 : 10:59:50
http://www.sqlteam.com/item.asp?ItemID=8866

That should get you started.

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2003-01-30 : 13:10:39
GREAT Article robvolk. Had to do something similar a while back for DB2 O/s 390. Not as elegant as what you proposed however. The article mention part 2, but I can't locat it, and there is no link to it.

Can you help me out?

Thanks

Brett

8-)

Go to Top of Page
   

- Advertisement -