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)
 Category tree query help!

Author  Topic 

ryanoc
Starting Member

25 Posts

Posted - 2007-03-07 : 15:35:05
I have a table with a parent, child, and grandchild relationship. Can anyone help me with a query that will return the child and grandchild of a parent? Heres a table that I have:

id | pid | name
----------------
3 | 0 | parentcat
4 | 3 | childcat
5 | 4 | grandchildcat

thanks for any help!

Ryan

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-07 : 16:57:51
Want to tell us what the result set is suppose to look like?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ryanoc
Starting Member

25 Posts

Posted - 2007-03-07 : 17:06:53
3 | 0 | parentcat
4 | 3 | childcat
5 | 4 | grandchildcat

there are other records in the table but this is what i need. i want to specify 3 as the id and get all children and grandchildren in a single query.

Thanks!
Ryan
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-07 : 17:11:19
It's like dejavu all over again

What version of SQL Server?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

ryanoc
Starting Member

25 Posts

Posted - 2007-03-07 : 17:24:55
sql 7. Heres a better display of what Im looking for...




Heres my table:

id pid name
--------------------------------
1 0 UntID
2 0 Vin Number
3 0 Make
4 3 Model
5 4 Model Number
6 0 Model Year
7 0 Vehicle Type
8 0 Odometer Miles



When I select 3 as the id I need these results:

id pid name
--------------------------------
3 0 Make
4 3 Model
5 4 Model Number
Go to Top of Page
   

- Advertisement -