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 |
|
maximus_vj
Yak Posting Veteran
88 Posts |
Posted - 2004-12-09 : 05:39:58
|
| Hello Everyone,I have a tree structure in a table and I want to get the whole subtree given a node.This is how my table looks:Node_ID----ParentNodeID----ChildCount-------------------------------------100-------------0---------------2101-------------100-------------3102-------------100-------------2103-------------101-------------0104-------------101-------------0105-------------101-------------0106-------------102-------------0107-------------102-------------0As you can see in this Node ID is the ID for the Node. ParentNodeID is the Node_ID of the parent. If ParentNodeID is 0 that means that it is the root node. And if the ChildCount is 0 it is the leaf node.The depth of the tree is not fixed.How do I write a SQL Query so that if I supply 100 I will get the whole sub tree from 100 i.e. all the above nodes. And if I supply 101 I will get 101,103,104,105. Similarly if I give 102 I should get 102,106,107.Thanks for your help,maximus |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
|
|
maximus_vj
Yak Posting Veteran
88 Posts |
Posted - 2004-12-10 : 00:28:20
|
| Thnx Corey !!!maximus |
 |
|
|
|
|
|