• The values that 'name' has are just for ordering porpoise, for easier visualization of the results...

    'name' actually has Accounting, Sales, Purchases, Human Resources, etc...

    So it can't be used for ordering...

    It start with the record with IdRoot = 0 and then it children and further down the level...

    The cursor works cause it gets ti IdRoot = 0, inserts it in a temp table and then it's children and for each child, inserts a record in the temp table and processes its children recursively.

    Pedro



    If you need to work better, try working less...