title: Group multiple result rows in the same row by one column in SQL Server 2008
body: <p>I am working with SQL Server 2008. I have a temp table which returns the this result:</p>
  
  <pre><code>ID      NAME        TYPE        REGION  DATE_HIRED
  --------------------------------------------------
  75038   GRUPO FOO   COMPANY A   EUROPE    201512
  75038   GRUPO FOO   COMPANY A   EUROPE    201511
  75038   GRUPO FOO   COMPANY A   EUROPE    201510
  </code></pre>
  
  <p>I want to get the date of hire of a company and all the information in the same row, and I want the result to be in a format like this:</p>
  
  <pre><code> ID       NAME       TYPE       REGION   DATE_HIRED1  DATE_HIRED2 DATE_HIRED3...
  75038   GRUPO FOO   COMPANY A   EUROPE    201512         201511      201510...
  </code></pre>
  
  <p>The possible dates of hire can be 4 (201512,201511,201510,201509), but a company cannot have a contract in one of those dates?</p>
  
  <p>How to query to get the above result using SQL Server 2008?</p>
  
  <p>I tried using a <code>PIVOT</code> in SQL Server 2008 but I failed. </p>
  
  <p>I suspect the <code>PIVOT</code> operator is what I need (according to this post, anyway), but I can't figure out how to get started, especially when the number of question_id rows in the table can vary. In the above example, it's 5, but in another query the table might be populated with 7 distinct questions.</p>