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)
 Propper way to query a table

Author  Topic 

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2006-09-13 : 11:54:24
For simplicity let's say I have a two table each have two columns

(ParentCategory,CurrentCat)
null,Shoes
shoes,Sneakers
Sneakers,Nike
Sneakers,Rebok
etc.

(CurrentCat,Product)
Nike,Jordans
Rebok,Shaqs


how could I query Sneakers and return
(Results)
Jordans
Shaqs

and also how could Query 'nike'
and get the catagory

Shoes,Sneakers,Nike

Please keep in mind this can go on far more then just the 3 levels, I stopped at the three to keep it simple. I'm thinking along the lines of a while exists and appending the string, but is this the best method?

Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2006-09-13 : 12:01:06
Are you v2005?
If so look at CTEs in bol - it has a bit on hierarchies.

If not do a search - there's stuff on this site and
http://www.nigelrivett.net/SQLTsql/RetrieveTreeHierarchy.html

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -