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 |
|
RogerSGI
Starting Member
9 Posts |
Posted - 2011-01-27 : 15:39:58
|
| Edit: I meant one column into three columns not three rows.wait it's actually many rows into one row with three columns, geez long dayI have a table that is feed from XML.I have three possibilities for info per ShipmentID but I need it to be queried into a single row with multiple columnsInput58921 400017658 158921 Ref 2 259461 01025564 159461 0419521 259563 354 3Query outputID Col1 Col2 Col358921 400017658 Ref 259461 01025564 041952159563 354This last ID 59563 the data is in Col3 while Col1 and Col2 are blank |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2011-01-27 : 16:53:20
|
SELECT ShipmentID AS ID,MAX(CASE WHEN TypeCol = 1 THEN DataCol ELSE NULL END) AS Col1,MAX(CASE WHEN TypeCol = 2 THEN DataCol ELSE NULL END) AS Col2,MAX(CASE WHEN TypeCol = 3 THEN DataCol ELSE NULL END) AS Col3FROM dbo.Table1GROUP BY ShipmentIDORDER BY ShipmentID N 56°04'39.26"E 12°55'05.63" |
 |
|
|
RogerSGI
Starting Member
9 Posts |
Posted - 2011-01-28 : 09:20:45
|
| Sweet, thanks for the help.RogerN 44°49'24.47" W 93°34'56.31" |
 |
|
|
|
|
|