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 |
|
sona_Sql
Starting Member
2 Posts |
Posted - 2009-08-27 : 07:29:40
|
| Hi All I am using Sql Server 2005.WOID AC ACC AL ALO1 2 3 5 112 5 113 2 3 5 114 2 5My structure looks like above.I need the result as:1 21 31 5 1 112 5 2 113 23 33 53 114 24 5Consider the first column as a parent and the rest are the child.The result is the combination of parent with the child.Please can anybody help me out how to do it? Thanks in advance. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-27 : 08:19:21
|
| One of the solutionsselect WOID, AC from tableunion allselect WOID,ACCfrom tableunion allselect WOID, AL from tableunion allselect WOID, ALO from tableorder by WOIDMadhivananFailing to plan is Planning to fail |
 |
|
|
waterduck
Aged Yak Warrior
982 Posts |
Posted - 2009-08-27 : 13:43:27
|
[code]DECLARE @Tempfun TABLE(WOID int, AC int, ACC int, AL int, ALO int)INSERT INTO @TempfunSELECT1, 2, 3, 5, 11 UNION ALL SELECT2, 5, 11,null,null UNION ALL SELECT3, 2, 3, 5, 11 UNION ALL SELECT4, 2, 5,null,nullSELECT WOID, colxFROM @TempfunUNPIVOT ( colx FOR cols IN (AC, ACC, AL, ALO) ) AS unpvt[/code] Hope can help...but advise to wait pros with confirmation... |
 |
|
|
sona_Sql
Starting Member
2 Posts |
Posted - 2009-08-30 : 07:13:06
|
| Hi Thank u so much for your replies.Madhivanan's solution worked well. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-31 : 01:37:38
|
quote: Originally posted by sona_Sql Hi Thank u so much for your replies.Madhivanan's solution worked well.
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|