Parent/Child Tree in SQL 7

  • Ok, I'm sure this is easy enough to do, but I can't get my head around it. If I have a table -

    
    

    IDNameParent
    ------------
    1first0
    2second0
    3third1
    4fourth3

    I want to write a query (or recursive stored procedure, etc) that will return:

    1first

    3third

    4fourth

    2second

    (basically a tree structure without formating)

    TIA

  • if you just want parent child then join back to the table

    If you want unlimited then you have to populate a temporary table.

    i.e populate records with a parent of 0 then populate records that relate to the records you have just populated, and is not in the table and carry on until no records are inserted. Then you can return the data from the temp table.

    Simon Sabin

    Co-author of SQL Server 2000 XML Distilled

    http://www.amazon.co.uk/exec/obidos/ASIN/1904347088


    Simon Sabin
    SQL Server MVP

    http://sqlblogcasts.com/blogs/simons

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply