I'm trying to execute the following in sql server express 2012
SELECT t,
MAX(CASE ItemID WHEN 1 THEN qun ELSE '' END) AS [Item-A],
MAX(CASE ItemID WHEN 2 THEN qun ELSE '' END) AS [Item-B],
MAX(CASE ItemID WHEN 3 THEN qun ELSE '' END) AS [Item-C],
MAX(CASE ItemID WHEN 4 THEN qun ELSE '' END) AS [Item-D],
MAX(CASE ItemID WHEN 5 THEN qun ELSE '' END) AS [item-E]
FROM
(
SELECT CONVERT(char(7),Production.Production.[Date] , 112)as t,
sum(Production.Production.Quantity) qun,
Production.Production.ItemID ItemID
FROM Production.Production
)AS e
GROUP BY e.t
But I am getting the error:
Msg 8120, Level 16, State 1, Line 8
Column 'Production.Production.Date' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.