title: SQL Server : Pivot Function Error
body: <p>I'm getting the following error:</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 2<br>
    Incorrect syntax near '('.</p>
  </blockquote>
  
  <p>When executing this query:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>I attempted to use both <code>YEAR</code> and <code>DATEPART</code>. The error is referencing the opening parentheses on the second <code>DATEPART</code>.</p>