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.
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.
It combines 7 tables and spits them out as below: (cut off the rest of the table to make easily readable)
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
Using this code (The current columns showing are tblprod.prodID, prodval.valueColumn, prodval.valueKey, tblprod.parentSKU, and tblprod.prodTitle )
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
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)
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.
An example table would look like below.
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
If anyone could offer any help I would seriously appreciate it, I just cannot get my head around it.
Sorry forgot to mention I am using SQL Server Management Studio
select max(Filter),min(Filter) from yourtable?