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)
 select table with 1 to many rel'ship with itself

Author  Topic 

PFunk
Starting Member

2 Posts

Posted - 2005-12-21 : 17:46:53
I have a table of categories and sub-categories like so:

CategoryID (PK)
ParentCategoryID
CategoryOrder

How do I select from the table so that the order of data is a main category followed by all its subcategories, then the next main category followed by its subcategories?

Cheers.

:)

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-22 : 02:33:12
Refer this
http://www.nigelrivett.net/RetrieveTreeHierarchy.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

PFunk
Starting Member

2 Posts

Posted - 2005-12-22 : 16:57:03
Thanks madhivanan.

Is there a way to do it using my existing structure?

CategoryID (PK) (varchar(100))
ParentCategoryID (varchar(100))
CategoryOrder (int)

Cheers.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-23 : 00:40:12
Try to simulate the logic used at that link

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -