|
Pavans
Starting Member
4 Posts |
Posted - 2010-06-24 : 04:19:01
|
| Hi All,A| || |C B||DA Is parent to BA is parent to CC is Parent to DA is parent to D -- The first four records in the below example shows it.also, A is child to itselfB is child to itselfC is child to itselfD is child to itself. The last four records in the below examples expalins that.For top_flag and bottom_flag the logic isfor the 1st row :A is the parent at the top level so Top_flag is 'Y' and B doesnt have a child so Bottom_Flag is 'Y'for the 2nd row:A is the parent at the top level so Top_flag is 'Y' and C has a child so Bottom_Flag is 'N'for the 3rd row:C is the parent and not at the top level so Top_flag is 'N' and D has no child so Bottom_Flag is 'Y'ChildLevel and ParentLevel are indicates what level the child and parent are.Result should be :Parent,Child,Top_flag,Bottom_flag,ChildLevel,ParentLevelA,B,Y,Y,2,1A,C,Y,N,2,1C,D,N,Y,3,2A,D,Y,Y,3,1A,A,Y,N,1,1B,B,N,Y,2,2C,C,N,N,2,2D,D,N,Y,3,3I have used the below query,WITH temp_A (s_id, id_over, id_under, TYPE_ID, t_tp, iteration ) AS(SELECT surr_id, t_id_over, t_id_under, TYPE_ID,t_tp,1FROMAWHERETYPE_ID in ('L', 'B')UNION ALL SELECT b.s_id, a.id_over, b.ID_UNDER, a.TYPE_ID,b.t_tp, a.iteration + 1FROM temp_A AS a, A AS bWHERE a.id_under = b.ID_OVERand b.TYPE_ID in ('L', 'B')and b.t_tp <> 'D')SELECT s_id, id_under, id_over, TYPE_ID,isrt_tp, iterationFROM temp_orgchartResult I am getting is:Parent,Child,IterationA,B,1A,C,1C,D,1A,D,2Any help is really appreciated.Thanks in AdvancePavanPavan |
|