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 |
|
matta0990
Starting Member
44 Posts |
Posted - 2011-08-26 : 08:40:41
|
| Hi, how do i PIVOT a table so that all the results returned back display accround the top as headers instead of a list format in a coloum.Thanx MatJ Smith |
|
|
flamblaster
Constraint Violating Yak Guru
384 Posts |
Posted - 2011-08-26 : 09:29:24
|
If you have MS SQL Server 2005 or later:http://msdn.microsoft.com/en-us/library/ms177410.aspxYou can also use Case expressionsEx:Select Sum(case when colA=SomeValue then 1 else 0 end) as 1stColHdr,Sum(case when colB=SomeValue then 1 else 0 end) as 2ndColHdr, etcFrom YourTableWhere SomeConditionsExist |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-26 : 09:31:06
|
| can you show as an example?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
matta0990
Starting Member
44 Posts |
Posted - 2011-08-26 : 09:42:32
|
| ATTRIBUTE_Name1 Al2O32 ARSENIC_TM3 ASH_AA4 ASH_AR5 ASH_DA6 ASH_FUSION_TEMPSo....... i want all these attribute names to display likeAl2O3 ARSENIC_TM ASH_AA ASH_AR ASH_DA ASH_FUSION_TEMPJ Smith |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-26 : 09:44:31
|
| and what should come as data within them?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
matta0990
Starting Member
44 Posts |
Posted - 2011-08-26 : 09:55:16
|
| err lets just sayValue1 1002 2003 3004 4005 5006 600from same tableJ Smith |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-26 : 10:09:30
|
| [code]SELECT MAX(CASE WHEN Attribute_Name='Al2O3' THEN Value ELSE NULL END) AS Al2O3,MAX(CASE WHEN Attribute_Name='ARSENIC_TM' THEN Value ELSE NULL END) AS ARSENIC_TM,...FROM Table[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|
|