tree -> display node + descendants + level


i have table T(id, name, parentid) that holds hierarchical data (parentid is foreign key for id).
i want to write a stored proc that takes a node as parameter and displays the node's descendants and each descendant's level in the tree.

all i've managed to do so far is a recursive stored proc that takes as paramater the root and displays the root's descendants.

any ideas ?



  • So, you have already written the part that displays the descendants? Does that mean the only part missing is the part that displays the level? If so, you could add a "count" parameter to the proc that gets incremented with each iteration. My SQL isn't all that hot, but the pseudo-code would something like
    int number(int i){
    print i
    if i > 0{
    return number(i - 1)
    return 0
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion