title: Split rows with same ID into columns
body: <p>I have a table that looks like this:</p>
  
  <pre><code>ID    Name
  1     John
  1     Maria
  1     Sam
  2     Lisa
  2     Martin
  </code></pre>
  
  <p>I would like to have an output like this:</p>
  
  <pre><code>ID    NAME1    NAME2    NAME3
  1     John     Maria    Sam  
  2     Lisa     Martin   NULL  
  </code></pre>
  
  <p>I don't want to use the <code>pivot</code> function because it won't give me this result (when tried this).</p>
  
  <p>The <code>ID</code> will only generate 3 rows with the same <code>id</code> nr so there for only 3 name columns.</p>
  
  <p>Finishing SP for this query:</p>
  
  <pre><code>INSERT INTO [Database].[dbo].[TEST]
  (
         [ID],
         [Contact1],
         [Contact2],
         [Contact3]
  )
  
  ;WITH CTE
  AS 
  (
  SELECT 
      ID,
      NAMN,
      ROW_NUMBER() OVER(PARTITION BY P_ID ORDER BY NAMN) AS RowNum
  FROM tabl1 
  WHERE VISA_EJ = 0
  )
  SELECT 
      [ID],
      [1] AS [Contact1],
      [2] AS [Contact2],
      [3] AS [Contact3]
  FROM CTE
  PIVOT(MAX(NAMN) for RowNum in ([1],[2],[3])) AS [Contacts]
  </code></pre>
  
  <p>Still get an error with the semicolon.</p>