title: SQL Combine Multiple rows into Multiple Columns
body: <p>I have been looking at the other example here and across the web and I just cannot wrap my head around how to do this. </p>
  
  <p>I have a site where I am pulling every piece of information on products into the one table to be viewed and then loaded into a csv/excel sheet. </p>
  
  <p>It combines 7 tables and spits them out as below: (cut off the rest of the table to make easily readable)</p>
  
  <pre><code>ID  Filter     FilterValue  ParentItem  ItemTitle             
  ---------------------------------------------------------------
  7   15         B            LE0001      LB PALETTE WHITE 127MM
  7   16         Yes          LE0001      LB PALETTE WHITE 127MM  
  7   18         Yes          LE0001      LB PALETTE WHITE 127MM
  7   20         Std          LE0001      LB PALETTE WHITE 127MM
  7   22         Yes          LE0001      LB PALETTE WHITE 127MM
  7   23         Polyester    LE0001      LB PALETTE WHITE 127MM
  7   25         White        LE0001      LB PALETTE WHITE 127MM
  7   26         127mm        LE0001      LB PALETTE WHITE 127MM
  </code></pre>
  
  <p>Using this code (The current columns showing are tblprod.prodID, prodval.valueColumn, prodval.valueKey, tblprod.parentSKU, and tblprod.prodTitle )</p>
  
  <pre><code>SELECT 
     tblprod.prodID as ID, prodval.valueColumn as Filter, 
     prodval.valueKey as FilterValue, tblprod.prodSKU as Item, 
     tblprod.parentSKU as ParentItem, tblprod.prodTitle as ItemTitle, 
     tblprod.prodConsumerTitle as ConsumerTitle, tblprod.itemGroup as ItemGroup, 
     tblprod.itemFamily as ItemFamily, tblprod.cutLengthCode as LengthCode, 
     tblprod.prodPackSize as PackSize, tblprod.prodMultQty as MultipleQuantity, 
     tblsu.ImportCode as SalesUnit, tblprod.prodPrice as SalesPrice , 
     tblprod.qtyDependent as QtyDep, tblprod.qtyTarget as Limit, 
     tblprod.targetPrice as Price, tblprod.prodLegacyImage as MainImage,
     catprod.IsPrimary as SafetyinMind, featlists.prodList as NEWLimited      
  FROM 
     [Eclipse].[dbo].[tbl_Product] AS tblprod
  LEFT JOIN 
     [Database].[dbo].[tbl_SalesUnit] AS tblsu ON tblsu.ID = tblprod.saleUnit
  LEFT JOIN 
     [Database].[dbo].[tbl_ProductFilter] AS prodfil ON prodfil.ProdID = tblprod.prodID
  LEFT JOIN 
     [Database].[dbo].[tbl_ProductFilterValues] AS prodval ON prodval.valueID = prodfil.valueID
  LEFT JOIN
     [Database].[dbo].[tbl_ProductstoFeaturedLists] AS prodlists ON prodlists.prodID = tblprod.prodID
  LEFT JOIN
     [Database].[dbo].[tbl_FeaturedLists] AS featlists ON featlists.ID = prodlists.listID
  LEFT JOIN 
     [Database].[dbo].[tbl_CategoryProducts] AS catprod ON catprod.prodID = tblprod.prodID
  </code></pre>
  
  <p>The important part is I want to combine the rows of the same ID, create column titles out of the Filter column (prodval.valueColumn) and fill them with their corresponding value (prodval.valueKey)</p>
  
  <p>My issue is I just have no idea how to accomplish this and I am lost when reading the other answers, secondly there are 19 filters and not every product will have all of them (as you can see the above product has 8) I am unsure if this will cause me any issues when I do this. The filters range from 15 to 33, all of them are used but just by different products.   </p>
  
  <p>An example table would look like below.  </p>
  
  <pre><code>ID  ParentItem  ItemTitle               Filter 15   Filter 16   Filter 17   Filter 18   Filter 19   Filter 20   Filter...
  7   LE0001      LB PALETTE WHITE 127MM  B           YES                     YES                     Std 
  </code></pre>
  
  <p>If anyone could offer any help I would seriously appreciate it, I just cannot get my head around it. </p>
  
  <p>Sorry forgot to mention I am using SQL Server Management Studio</p>