swad swad - 3 months ago 6
SQL Question

How to do Pivot in SQL having three fields?

I have a table called product and want to perform pivot operation and looking for following results:

Input Table

OutPut Required:

OutPut

How to do Pivot in SQL having three fields?

Answer
Select * from
(SELECT  
    *
FROM
    Product ) t
Pivot (MAX(Value) FOR Attribute in ([FLAVOUR], [INCENPRODUCT], [MANUFACTUREDBY], [PRODUCTBRAND], [PRODUCTCATEGORY], 
                                    [PRODUCTCATEGORY1], [PRODUCTCATEGORY2A], [PRODUCTCATEGORY2B]) ) P
Comments