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)
 Traversing a node with childs of any no. of levels in a tree

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-25 : 08:14:37
ashy writes "I have a scenario of traversing a tree like structure in sql, exactly like the structure specified in

http://www.4guysfromrolla.com/webtech/sqlguru/q022000-2.shtml

Well, fine, this helps out in traversing the entire tree.
But i need something specific. For eg: If i give any particular node, at any level, may be as a parameter,

I need an sql query without any recursive function to get the node and its child's values of any levels?

Thanks
Ashy"

Kristen
Test

22859 Posts

Posted - 2005-08-25 : 08:25:24
Hi Ashy, Welcome to SQL Team!

We store:

Level
Parent ID (next higher level)
Sibbling ID ("Next Elder sibbling" at the same level, NULL=FirstBorn)
a Sequence number (OrderBy will provide "walking order" for the whole tree)
Path (concatenation of the ID numbers of all parents stored as a fixed length, or delimited, string)

For a given node we can find any parent by "splitting" its Path, and all children where their Path "starts with" the path of the node in question, or where the ParentID matches the current NodeID (depending on immediate children only, or all-generations of children)

Dunno if that helps at all though!

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-25 : 08:58:17
See if these are helpful
http://www.seventhnight.com/treestructs.asp
http://www.nigelrivett.net/RetrieveTreeHierarchy.html

Madhivanan

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

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-08-25 : 09:05:36
cached copies of mine... (i'm moving so my site is down)
Part1 Part 1
Part2 Part 2
Part3 Part 3


Corey

Co-worker on The Wizard of Oz "...those three midgets that came out and danced, the freaked me out when I was little. But they are ok now."
Go to Top of Page
   

- Advertisement -