• Dear Experts

    I don't think we can use the same query.

    In the first row we don't want output 101/1 for parentID=101,childID=1

    Instead the output should be 101/1/6 in the first row since 1 has the branch 6.

    Second row 1/6 remains the same since 6 doesn't have any branch

    In the third row we want the output to be 101/2/4 not 101/2.

    In the fourth row output 2/4 remains the same since 4 don't have any branch.

    So it is filtering the Parent ID on row by row basis.

    Please refer the output as follows and view the attached images for further information.

    select * from CTE it should appear as follows includes output column for all rows.

    PC

    1011

    output : 101/1/6

    PC

    16

    output :1/6

    PC

    1012

    output :101/2/4

    PC

    24

    output :2/4

    PC

    25

    output :2/5/6

    PC

    56

    output : 5/6

    PC

    57

    output :5/7

    PC

    1013

    output :101/3/5

    PC

    35

    output :3/5