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 2005 Forums
 Transact-SQL (2005)
 building a menu, can a query do this?

Author  Topic 

tehprince
Starting Member

9 Posts

Posted - 2007-12-18 : 13:11:59
I'm looking to build a menu / sitemap out of my 2005 SQL Server database, an example of my table structure is:

ID PageTitle ParentID
=======================================
1 Home 0
2 About Us 1
3 Contact Us 1
4 About Us / Sub 1 2
5 About Us / Sub 2 2
6 About Us / LVL 3 5

So essentially this menu should display as follows:
Home
About Us
About Us / Sub 1
About Us / Sub 2
About Us / LVL 3
Contact Us

Is it possible to write a query that would output menu in that specific order?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-12-18 : 13:20:20
Yes. Take a look at recursive CTE (Common Table Expression) in Books Online.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -