Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
mahesh.sanka
Starting Member
18 Posts |
Posted - 2014-02-05 : 06:47:48
|
Hi All,I have one table which consists of data in the following mannerChild Parent ZN1 NSZN2 NSA1 ZN1A3 Zn1A2 Zn2A4 Zn2IT1 A4It2 A3It3 A2It5 A1Now i want to display the information in the follwing manner.Zn1 NSA1 Zn1It5 A1A3 Zn1It2 A3Zn2 NSA2 Zn2It3 A2A4 Zn2IT1 A4Thanks & Regards,Mahesh Kumar Sanka |
|
bitsmed
Aged Yak Warrior
545 Posts |
Posted - 2014-02-05 : 12:45:32
|
Whats the logic?You could do:select child ,parent from yout_table order by case child when 'ZN1' then 0 when 'A1' then 1 when 'It5' then 2 when 'A3' then 3 when 'It2' then 4 when 'ZN2' then 5 when 'A2' then 6 when 'It3' then 7 when 'A4' then 8 when 'IT1' then 9 else 10 end |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-10 : 09:02:13
|
quote: Originally posted by mahesh.sanka Hi All,I have one table which consists of data in the following mannerChild Parent ZN1 NSZN2 NSA1 ZN1A3 Zn1A2 Zn2A4 Zn2IT1 A4It2 A3It3 A2It5 A1Now i want to display the information in the follwing manner.Zn1 NSA1 Zn1It5 A1A3 Zn1It2 A3Zn2 NSA2 Zn2It3 A2A4 Zn2IT1 A4Thanks & Regards,Mahesh Kumar Sanka
Use a recursive cte for thisseehttp://technet.microsoft.com/en-us/library/ms186243(v=sql.105).aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|