this is (maybe) an already asked question… but i’ve some difficul to solve my problem.
I need to transpose to column a row-based query.
I explain:
This is my actual query result
Year Month Value
2010 Jan 19
2010 Feb 10
...
I need
Year Jan Feb ... Dec
2010 19 20 ... ...
2011 11 .. ...
Actually, my main query is very simple..
SELECT SUM(QTYCALC) AS TOT, YEAR(SCHEDSTART) AS MyYear, MONTH(SCHEDSTART) AS MyMonth
FROM PRODTABLE
GROUP BY YEAR(SCHEDSTART), MONTH(SCHEDSTART)
Thanks in advance
You need to use
PIVOTto achieve that – for explanation and some examples see http://msdn.microsoft.com/en-us/library/ms177410.aspx and http://www.simple-talk.com/community/blogs/andras/archive/2007/09/14/37265.aspxAnother option would be:
You should check both (
PIVOTand this) regarding performance/execution plan…