June 29, 2009 at 5:02 am
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
June 29, 2009 at 5:37 am
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
June 29, 2009 at 6:25 am
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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy