March 3, 2004 at 12:18 pm
Hi All,
I have a table used for a treeview control. The table looks like this:
CategoryID | ParentCategoryID | CategoryName |
1 | -1 | parent |
2 | 1 | child |
3 | 2 | child of child |
Given a CategoryID how could I work all the way back up the tree to get the top or root level CategoryID?
In this example given a CategoryID of 3 I would need to work all the way back up to arrive a the top level and return a CategoryID of 1 (ParentCategoryID of -1 signifies top level)
Since this is a tree view there could be many nodes so some sort of loop/recursive function would be needed I guess until I get to -1, but despite my research I just don't know where to start...
Any help greatly appreciated!!
Sal
March 4, 2004 at 6:48 pm
In my opinion, adding two another columns is a better option,but it will need extra maintenance efforts. If the tree structure is changed frequently, keeping the table simple is better.
You can create UDF to get the whole structure based on the specified root ID. That's easy and much more flexible.
March 4, 2004 at 9:59 pm
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply