I have a stored procedure that returns data in the format of:
Date | Unit A Count | Unit B Count | Unit C Count
2010 | 335 | 52 | 540
2011 | 384 | 70 | 556
2012 | 145 | 54 | 345
Internally this stored procedure makes a call to another stored procedure, so I can’t nest it again.
What I’m after is a way to pivot the above output so it looks like this:
| 2010 | 2011 | 2012
Unit A Count | 335 | 384 | 145
Unit B Count | 52 | 70 | 54
Unit C Count | 540 | 556 | 345
Edit: The StorProc is called with 3 parameters and I do need to keep the original output.
Any ideas?
I’m using SQL Server 2005, Visual Studio 2008, C# with the output going to an .aspx page.
If you want to transform the results of your stored procedure, then you will need to use UNPIVOT and PIVOT to get your final product:
See a SQL Fiddle with a Demo
You want to transform these values in your store procedure, then you would have to post that full query so we could see it.