Hi @Shivendoo Kumar ,
Please refer to:
declare @test table(col1 char(25),col2 char(25),col3 char(25),col4 char(25),amount int)
insert into @test values('storeprofit','grossprofit','netsales','sales',2222),
('storeprofit','grossprofit','purchases','purchases',2223),
('storeprofit','totaldirectcosts','employeeexpenses','spuer',2224),
('storeprofit','totaldirectcosts','occupancyexpenses','rent&rates',2225),
('storeprofit','totaldirectcosts','advertisingexpenses','advertisingexpenses',2226)
select null parent,max(col1) child,1 as level from @test
union all
select distinct col1 parent, col2 child,2 as level from @test
union all
select distinct col2 parent, col3 child,3 as level from @test
union all
select distinct col3 parent, col4 child,4 as level from @test
union all
select distinct col4 parent, cast(amount as char(15))child,5 as level from @test
Best Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.