title: SQL make rows into columns, PIVOT maybe
body: <p>I have an MS SQL Server with a database for an E-commerce storefront.</p>
  
  <p>This is some of the tables I have:</p>
  
  <pre><code>Products:  
  Id | Name | Price
  
  ProductAttributeTypes: -Color, Size, Format  
  Id | Name
  
  ProductAttributes: --Red, Green, 12x20 cm, Mirrored  
  Id | ProductAttributeTypeId | Name
  
  Orders:  
  Id | DateCreated
  
  OrderItems:  
  Id | OrderId | ProductId
  
  OrderItemsToProductAttributes: --Relates an OrderItem to its product and selected attributes  
  OrderItemId | ProductAttributeId | ProductAttributeTypeId | ProductId
  </code></pre>
  
  <p>I want to select from the OrderItems table, to see which items have been purchased.</p>
  
  <p>To see what kind of variants (ProductAtriibutes) was selected, I want those as "dynamic" columns in the resultset.</p>
  
  <p>So the resultset should look like this:</p>
  
  <pre><code>OrderItemId | ProductId | ProductName | Color | Size | Format  
         1234         123   Mount. Bike   Red     2x20   Mirror
  </code></pre>
  
  <p>I don't know if PIVOT is the thing to use? I'm not using any aggregate functions, so I guess not...</p>
  
  <p>Is there any SQL Ninjas that can help me out?</p>