• First, here's the result set from my solution for this problem...

    Results:

    sId scode ParentID sName Hierarchy

    --- ----- -------- ----- -------------------

    1 11 0 a 11\111

    2 111 1 b 11\111\1111

    3 1111 2 c 11\111\1111\11111

    4 11111 3 d 11111

    (4 row(s) affected)

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)