title: SQL pivot to flatten rows into columns
body: <p>I have a source table that looks like this:</p>
  
  <pre><code>+--------------+----------+------+------------+-----------+
  | vehicleindex | parentid | year |    make    |   model   |
  +--------------+----------+------+------------+-----------+
  |            1 |        1 | 2007 | TOYOTA     | SIENNA LE |
  |            2 |        1 | 2005 | VOLKSWAGEN | JETTA GLS |
  +--------------+----------+------+------------+-----------+
  </code></pre>
  
  <p>I'd like to select from this table such that the output looks like this:</p>
  
  <pre><code>+-------+--------+-----------+-------+------------+-----------+
  | year1 | make1  |  model1   | year2 |   make2    |  model2   |
  +-------+--------+-----------+-------+------------+-----------+
  |  2007 | TOYOTA | SIELLA LE |  2005 | VOLKSWAGEN | JETTA GLS |
  +-------+--------+-----------+-------+------------+-----------+
  </code></pre>
  
  <p>How can I accomplish this on a SQL Server database with a pivot? There will always be either 1 or 2 vehicles in the source table. In the case where there's 1 vehicle, I would expect <code>Year2</code>, <code>Make2</code> and <code>Model2</code> to be <code>NULL</code>.</p>