title: How can I rotate the results of a query in SQL Server 2005?
body: <p>I would like to be able to rotate the results of a SQL Query so that instead of the results being returned in a series of rows the results are returned as a single row with multiple columns.
  For example with the following table.</p>
  <pre><code>Create Table TestData 
  (
  things varchar(25)
  )
  
  Insert into TestData values ('Thing1') 
  Insert into TestData values ('Thing2')
  Insert into TestData values ('Thing3')
  Insert into TestData values ('Thing4')
  </code></pre>
  <p>I would like a select statement like <code>Select things from TestData</code></p>
  <p>to return something like
  Thing1 Thing2 Thing3 Thing4</p>
  <p>rather than</p>
  <ol>
  <li>Thing1</li>
  <li>Thing2</li>
  <li>Thing3</li>
  <li>Thing4</li>
  </ol>
  <p>Thanks in advance for the help.</p>
  <p>Update:</p>
  <p>After seeing the recommendation by Gratzy to use Pivot I found I can get the desired result by adding an identity column to the table like so.</p>
  <pre><code>Create Table TestData 
  (
      id int identity,
      things varchar(25)
  )
  </code></pre>
  <p>and then running the following.</p>
  <pre><code>SELECT *
  FROM TestData
  PIVOT
  (
      MAX(Things)
      FOR [ID] IN ([1],[2],[3],[4])
  )
  AS Result
  </code></pre>