Howdy, Stranger!

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

Categories

tree -> display node + descendants + level

ILoveChocolateILoveChocolate Member Posts: 1
hi,

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 ?

thanks

Comments

  • bubbatremellbubbatremell Member Posts: 39
    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
    [code]
    int number(int i){
    print i
    if i > 0{
    return number(i - 1)
    }
    else{
    return 0
    }
    }
    [/code]
Sign In or Register to comment.