• an example of what Sean is asking you for: a CTE or CREATE TABLE with his first post:

    With MyCTE (PRNT,CHLD,POS)

    AS

    (

    SELECT '1050000','1000000','1' UNION ALL

    SELECT '1050000','5000000','2' UNION ALL

    SELECT '1050001','1000004','1' UNION ALL

    SELECT '1050001','5000002','2' UNION ALL

    SELECT '1000000','1010000','1' UNION ALL

    SELECT '1000000','1010001','2' UNION ALL

    SELECT '1000000','3030000','3' UNION ALL

    SELECT '1010000','2020000','1' UNION ALL

    SELECT '1010001','2030000','1'

    )

    select * from MyCTE where

    PRNT

    in

    ('1050000',

    '1000000',

    '1010000',

    '1010001')

    order by case

    PRNT

    when '1050000' then 1

    when '1000000' then 2

    when '1010000' then 3

    when '1010001' then 4

    end , POS ASC

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!