title: Convert Columns of Data to Rows of data in SQL Server
body: <p>I'm trying to learn how to import data from a csv file to my database and then reorganise it into my tables. I have imported a very simple set of data into a table called ' CSVTest_Match' that looks like this:</p>
  
  <pre><code>HEADER          DATA             --(Column Names)
  --------------- --------------
  Home Team       Barnsley
  Away Team       Wigan
  Kick Off Time   14:02
  Kick Off Date   03/08/2013
  Home Goals      0
  Away Goals      4
  </code></pre>
  
  <p>The values in both columns are VARCHAR's at this point. I would like to transform this data to look like this:</p>
  
  <pre><code>HOMETEAM   AWAYTEAM   KICKOFFTIME   KICKOFFDATE   HOMEGOALS   AWAYGOALS  -- (Column Names)
  ---------- ---------- ------------- ------------- ----------- ----------
  Barnsley   Wigan      14:02         03/08/2013    0           4
  </code></pre>
  
  <p>At this point it would be useful if the data was converted to VARCHAR, DATETIME, TINYINT values as appropriate.
  I've been getting rather confused trying to work out how to use PIVOT to do this so I would really appreciate some help.</p>
  
  <p>EDIT: I finally figured it out. The code required was:</p>
  
  <pre><code>SELECT * FROM 
  (SELECT Header, Data FROM CSVTest_Match) AS T
  PIVOT (Min(Data) FOR Header IN ([Home Team], [Away Team], [Kick Off Time], 
                  [Kick Off Date], [Home Goals], [Away Goals])) AS T2
  </code></pre>