• Something like this is what Dwain is talking about.

    create table #Something

    (

    ChildID int,

    ChildName varchar(20),

    ParentID int,

    PID int

    )

    insert #Something

    select 100, 'Bingo', 200, 1 union all

    select 101, 'Pingo', 201, 1 union all

    select 102, 'Zingo', 201, 1 union all

    select 100, 'Bingo', 201, 2 union all

    select 101, 'Pingo', 200, 2 union all

    select 102, 'Zingo', 201, 2 union all

    select 100, 'Bingo', 201, 3 union all

    select 101, 'Pingo', 201, 3 union all

    select 102, 'Zingo', 200, 3 union all

    select 100, 'Bingo', 200, 4 union all

    select 101, 'Pingo', 201, 4 union all

    select 102, 'Zingo', 200, 4

    select * from #Something

    drop table #Something

    OK so we have a table. However I don't get the relationship here. None of these rows have a ParentID that exists. What is PID? Your explanation of what you want is incredibly unclear.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/