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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-09-15 : 08:13:10
|
| The stored procedure (sp) returns fields as follows: YearQuarter Field1 Field2 Field3 Field4 null 5.33 5.6 4.2 5 2010 -1.43 -3.5 2.54 3.1 Q2 2010 2.5 4.3 2.2 8.1 Q1 2011 -2.4 9.4 4.3 1.2 How can I show this as follows please? null 2010 Q2 2010 Q1 2011 Field1 5.33 -1.43 2.5 -2.4Field2 5.6 -3.5 4.3 9.4Field3 4.2 2.54 2.2 4.3Field4 5 3.1 8.1 1.2 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-09-15 : 11:33:07
|
| [code]SELECT Field,[Null],[2010],[Q2 2010],[Q1 2011]FROM(SELECT ISNULL(YearQuarter,'Null') AS YearQuarter,Field,ValFROM tableUNPIVOT ( Val FOR Field IN ([Field1],[Field2],[Field3],[Field4]))u)mPIVOT (MAX(Val) FOR YearQuarter IN ([Null],[2010],[Q2 2010],[Q1 2011]))p[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-09-15 : 11:49:23
|
| The fields in YearQuarter in () are dynamic and can change depending on parameters, etc.Can it be dynamic?Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-09-16 : 03:57:36
|
| Thank you |
 |
|
|
|
|
|
|
|