I am trying to get the path from the root node to its children using SQL server.
The source data looks like :
The target should look like :
As I am going to implement this in an ETL tool exclusively using the ETL transformations, I would like to achieve this output without using CONNECT BY equivalent approach. Below query gets me the result and a few more records :
select case when level02.geography_02 is not NULL
then '3'
else case when level01.geography_02 is not null
then '2'
else case when root.geography_02 is not null
then '1'
end
end
end as levels,
root.geography_01 as root, root.geography_02 as super_parent,
case when level01.geography_02 is not null
then level01.geography_02
else ''
end as parent,
case when level02.geography_02 is not null
then level02.geography_02
else ''
end as child
from geo_table root
left join geo_table level01
on root.geography_02 = level01.geography_01
left join geo_table level02
on level01.geography_02 = level02.geography_01
Can you please on how to get the desired output?