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 |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-10-29 : 08:30:48
|
Adam writes "Let us say that i have made a query with joins. The result from this query looks somthing like this:Value column NameColumn------------ -------------1 A2 A3 A4 A5 A6 B7 B8 B9 B10 B. .. .. . I would like to display this data "turned 90 degrees" where the name columns groups (A,B,...) are columns in a table and the value columns data are the rows, like this:A B .------ ------- ------1 6 .2 7 .3 8 .4 9 .5 10 . Is there a way to do this in one sql statement?I would appreciate any help in this matter.RegardsAdam Bervenstahl" |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-10-29 : 08:31:13
|
Cross tabs to the rescue!http://www.sqlteam.com/SearchResults.asp?SearchTerms=cross+tab |
|
|
MakeYourDaddyProud
184 Posts |
Posted - 2003-10-29 : 08:43:14
|
In order to do that, you are transforming elements of metadata (column names) from data in a table. Some kind of dynamically built SQL string using EXEC(string) would be needed. Nasty!Anyway, In the transform, what would you expect the display to look like if, say B did not have '10' as a value? Would there be a null?Furthermore, how did your design process allow this to happen?Daniel Small MIAPwww.danielsmall.com IT Factoring |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2003-10-29 : 21:52:44
|
Not nasty at all, this does it all rather nicely:http://www.sqlteam.com/item.asp?ItemID=2955 |
|
|
|
|
|