I am working on a cross tab query in SQL Server 2008. Everything appear fine apart from this error I am getting.
Here is my code:
select * from
(select ITEM_CODE,NET_PRODUCTION_QUANTITY,RAW_MATERIAL_CODE,DATE_ID from dbo.ODST_PRODUCTION_TRANS
) n
pivot
(sum(NET_PRODUCTION_QUANTITY) for datename(month,DATE_ID) In ([January],[February],[March],[April],[May],[June])) as pvt
where RAW_MATERIAL_CODE = 'X' and DATE_ID between '01-Jan-11' and '30-Jun-11'.
The problem is where the datename(month,date_id) but I can’t figure it out. Can anyone give me a solution?
Thanks in advance
I don’t think the FOR part of a pivot can be a calculated value at the time of pivot and it must be in your result set.