Hi Experts,I need to denormalizing the below table:CREATE TABLE #temp( Id int ,category int ,Parent_id int ,Lvl tinyint ,Name varchar(20))insert into #tempSELECT 1,1,null,1,'World' UNION ALLSELECT 2,1,1,2,'Asia' UNION ALLSELECT 3,1,2,3,'India' UNION ALLSELECT 4,2,null,1,'a' UNION ALLSELECT 5,2,null,1,'d' UNION ALLSELECT 6,2,5,2,'dd' UNION ALLSELECT 7,2,4,2,'aa' UNION ALLSELECT 8,2,7,3,'aaa' UNION ALLSELECT 9,2,6,3,'ddd' UNION ALLSELECT 10,2,9,4,'dddd' UNION ALLSELECT 11,2,8,4,'aaaa' UNION ALLSELECT 12,2,8,4,'bbbb' UNION ALLSELECT 13,2,8,4,'cccc' UNION ALLSELECT 14,1,2,3,'china' --Expected Output:Id category Level1_id Level1_Name Level2_id Level2_Name Level3_id Level3_Name Level4_id Level4_Name Level5_id Level5_Name1 1 1 World 2 Asia 14 china NULL NULL NULL NULL2 1 1 World 2 Asia 3 India NULL NULL NULL NULL3 2 4 a 7 aa 8 aaa 11 aaaa NULL NULL4 2 4 a 7 aa 8 aaa 12 bbbb NULL NULL5 2 4 a 7 aa 8 aaa 13 cccc NULL NULL6 2 5 d 6 dd 9 ddd 10 dddd NULL NULL
Currenlty I am achieving this with joins .. but there could be a better way to do this. Thanks!