Pivot Help

  • Hi Guys

    I need help pivoting the following

    SELECT [ID],[code_name],,[retail_price] FROM products

    1 | Rice & Beans | Small | 10.00

    2 | Rice & Beans | Medium | 15.00

    3 | Rice & Beans | Large | 20.00

    TO be Pivot as follow

    SELECT [DESC],[Small],[Medium],[Large] FROM Pivot_Table

    Rice & Beans | 10.00 | 15.00 | 20.00

    This is my code but it is not working as expected, I am getting NULL value for the description

    SELECT [Desc], ISNULL([small],0) AS Small,ISNULL([medium],0) AS Medium,ISNULL([large],0) AS Large
    FROM
    (
    SELECT [code_name],,[retail_price] FROM products
    ) p
    PIVOT
    (
    SUM([retail_price])
    FOR [Size] IN ([Desc],[small],[medium],[large])
    ) AS pvt

    • This topic was modified 1 hour, 4 minutes ago by  mashispano.

Viewing 0 posts

You must be logged in to reply to this topic. Login to reply