• peterausger (4/27/2015)


    ------ create table

    create table test222(sid bigint, scode nvarchar(50), parentid bigint, sname nvarchar(50))

    insert into test222 values (1, '2323', 0, 'iam a boy')

    insert into test222 values (2, '23231000', 1, 'boy')

    insert into test222 values (3, '23232', 1, 'boo')

    insert into test222 values (4, '232321', 3, 'bo')

    insert into test222 values (5, '23232110', 4, 'boyy')

    insert into test222 values (6, '23232190', 4, 'gril')

    insert into test222 values (7, '232329', 3, 'body')

    insert into test222 values (8, '23232910', 7, 'girll')

    insert into test222 values (9, '23232990', 7, 'boy')

    insert into test222 values (10, '23233000', 1, 'bo')

    insert into test222 values (11, '232390', 1, 'nh')

    insert into test222 values (12, '23239010', 10, 'ui')

    insert into test222 values (13, '23239020', 10, 'dert')

    insert into test222 values (14, '23239030', 10, 'hyui')

    insert into test222 values (15, '23239040', 10, 'nji')

    insert into test222 values (16, '23239090', 10, 'vfr')

    iam searching for 2323...

    the exepected op is as follows

    1 (1 should have childs like 2,3,10,11 as its child))

    2 ( should have nothing) 3(should have 4,7 as its child) 10(should have 12,13,14,15,16 as its child) 11

    4(should have 5,6 as its child) 7(should have 8,9 as its child) 12

    5 , 6 8 9 13

    14

    15

    16

    Not really seeing what you are trying accomplish or what your result set should look like.

    How do you link the parent/child records?