I'm getting the following error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
When executing this query:
SELECT
'Average Total Comp' AS AverageTotalComp,
[2016], [2015], [2014]
FROM
(SELECT
DATEPART(yyyy, [Fiscal Year End Date]),
[Total Compensation ($)]
FROM
dbo.MDexec e) AS SourceTable
PIVOT
(AVG([Total Compensation ($)])
FOR DATEPART(yyyy, [Fiscal Year End Date])
IN ([2016], [2015], [2014])) AS PivotTable;
I attempted to use both YEAR and DATEPART. The error is referencing the opening parentheses on the second DATEPART.