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.
Author |
Topic |
BeTheBall
Starting Member
1 Post |
Posted - 2010-07-29 : 11:50:15
|
Way over my head here. I have a table that looks like this:officeID | officeName | parentOfficeID1 Main NULL2 Sub1 13 Sub2 14 Sub1ofSub1 25 Sub2ofSub1 26 Sub1ofSub2 37 Sub1ofSub1ofSub2 6I want to be able to pass in an officeID and have the db return the office that matches the officeID I pass in plus all it's parents. So, if I pass in officeID 7, the query needs to return officeID7, officeID6, officeID3 and officeID1.I know the query has to be recursive, but that's about as much as I know. My experience thus far has been limited to pretty straight-forward SELECT, UPDATE and DELETE statements.Any help will be appreciated.- Duane - |
|
X002548
Not Just a Number
15586 Posts |
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2010-07-29 : 12:28:02
|
Anyone that is looking into hierarchy, should be aware of this method. I really like this method if you are going to be running a lot of queries where you want to return all child nodes.It's written for mysql, but same principals work for sql server 2005http://dev.mysql.com/tech-resources/articles/hierarchical-data.html Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
|
|