title: T-SQL Pivoting not working
body: <p>I am doing some training on T-SQL database Northwind using SQL Server 2008R2.</p>
  
  <p>I am trying to pivot some data using the query below but it keeps returning the following error:</p>
  
  <blockquote>
    <p>Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword
    'WITH'. Msg 170, Level 15, State 1, Line 16 Line 16: Incorrect syntax
    near '('.</p>
  </blockquote>
  
  <pre><code>WITH PivotData AS
  (
  SELECT
          [OrderID],
          [CustomerID], 
          [Freight] 
  
  FROM [Northwind].[dbo].[Orders]
  )
  SELECT 
      [OrderID], 
      [10248],
      [10249],
      [10250]
  FROM PivotData
  PIVOT( SUM(Freight) FOR [CustomerID] IN ([10248],[10249],[10250])) AS P
  </code></pre>
  
  <p>Best Regards,</p>
  
  <p>Dan</p>