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 |
|
Rocko
Starting Member
26 Posts |
Posted - 2007-12-27 : 15:13:16
|
| Hello Friends,Normally each row from the result set represents a row of a table. If a table has 2 rows representing number of orders per day: SystemID | OwnerID | Notes------------------------------------------------1 | 10 | blah12 | 11 | blah22 | 12 | blah3I would like to orient this row horizontal like this:SystemID | 1 | 2 | 3 -------------------------------------OwnerID | 10 | 11 |12 Notes | blah1 | blah2 | blah3What techniques should I use in order to achieve such a result?The number of the systems that will display each time may vary. Something like this site: http://www.wikimatrix.org/compare/%40Wiki+MediaWiki+ScrewTurn-WikiThanks in advance!Rocco |
|
|
PurpleSun
Yak Posting Veteran
50 Posts |
Posted - 2007-12-27 : 16:40:47
|
| try these:[url]http://www.codecomments.com/message550596.html[/url][url]http://ryanfarley.com/blog/archive/2005/02/17/1712.aspx[/url] |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-12-27 : 22:02:56
|
use the PIVOT operator KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2007-12-28 : 01:22:40
|
| declare @sample table (SystemID int,OwnerID int,Notes varchar(100))insert @sampleselect 1 ,10 ,'blah1'union allselect 2 , 11 ,'blah2'union allselect 3 , 12 ,'blah3'SELECT 'OwnerID' AS SystemID,[1],[2],[3]FROM (SELECT SystemID,CAST(OwnerID AS VARCHAR(100)) AS OwnerID FROM @sample) AS pPIVOT (MAX(OwnerID) FOR p.SystemID in ([1],[2],[3])) AS pvtUNION ALLSELECT 'Notes' AS SystemID,[1],[2],[3]FROM (SELECT SystemID,Notes FROM @sample) AS p1PIVOT (MAX(Notes) FOR p1.SystemID in ([1],[2],[3])) AS pvt1 |
 |
|
|
|
|
|
|
|