I am having trouble using the pivot command - I am getting the following error
"Invalid column name '2013-03-22'. Invalid column name '2013-03-29'. Invalid column name '2013-04-05'. Invalid column name 'Volume'. Invalid column name 'Week Ending Date'."
when running this code
SELECT *
FROM
(
SELECT [Area],
[Region],
[Channel],
[Controller],
[2013-03-22] AS _dt1,
[2013-03-29] AS _dt2,
[2013-04-05] AS _dt3
FROM [DataTable]
) AS SourceTable
PIVOT
(
SUM ([Volume])
FOR [Week Ending Date] IN ([2013-03-22], [2013-03-29], [2013-04-05])
) AS PivotTable
It seems to fit the correct format.. any ideas?
_dt1,_dt2, etc in your subquery so the columns[2013-03-22], [2013-03-29], [2013-04-05]don't exist. You need to use the names of the aliases or skip the alias. Plus you have no column namedVolume, orWeek Ending Date.volumecolumn in your subquery. If the column doesn't exist in the subquery it can't sum it. What column in your subquery contains the volume value? Can you create a SQL Fiddle with some sample data? Or even edit your question to include sample data?