title: How to convert row values to columns with dynamic columns count?
body: <p>I have the following data:</p>
  
  <pre><code>DECLARE @DataSource TABLE
  (
       [ColumnA] INT
      ,[ColumnB] INT
      ,[ColumnC] INT
  )
  
  INSERT INTO @DataSource ([ColumnA], [ColumnB], [ColumnC])
  VALUES   (5060,1006,100118)
          ,(5060,1006,100119)
          ,(5060,1006,100120)
          ,(5060,1007,100121)
          ,(5060,1007,100122)
          ,(5060,1012,100123)
  
  SELECT [ColumnA]
        ,[ColumnB]
        ,[ColumnC]
  FROM @DataSource
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/7uyo2.png" alt="enter image description here"></p>
  
  <p>and I need to converted like this:</p>
  
  <p><img src="https://i.stack.imgur.com/yz27s.png" alt="enter image description here"></p>
  
  <p>The difficult part is that the data is dynamic (I do not know how many columns I will have) and I am not able to use a standard pivot here because the values in <code>ColumnC</code> are different and as a result I am going to have as many columns as values appears in <code>ColumnC</code>.</p>
  
  <p>Is there any technique to achieve this?
  Any kind of help (answers, articles, suggestions) will be appreciated.</p>