To Pivot or not to Pivot

  • Hi All,

    I want to be able to transform the following data

    [font="Courier New"]

    Name Month Year Value

    Rod 1 2009 10.5

    Jane 1 2009 11

    Freddy 1 2009 12

    Rod 2 2009 10

    Jane 2 2009 10

    Freddy 2 2009 13.1

    [/font]

    into

    [font="Courier New"]

    Name 1-2009 2-2009

    Rod 10.5 10

    Jane 11 10

    Freddy 12 13.1

    [/font]

    Can this be done with a pivot or not?

    Cheers,

    Andez

  • Hi,

    yes you can use pivot in the following way

    SELECT Name,[1] as [1-2009],[2] as [2-2009]

    FROM

    (

    SELECT NAME,Month,Year,Value

    FROM #t

    ) p

    PIVOT

    (

    MAX (Value)

    FOR [MONTH] IN

    ([1],[2])

    ) AS pvt

    Parul

  • Thanks Parul, that works fine.:-)

Viewing 3 posts - 1 through 2 (of 2 total)

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