Make rows columns in sql server 2005

  • I think I got to a point where I can display the result by date.

    SELECT[1/7/2009],

    [1/9/2009],

    [1/11/2009],

    [1/13/2009],

    [1/15/2009]

    FROM(SELECT[Date],

    [Count],

    MediaBuyer

    FROM#t

    ) p PIVOT (SUM([Count])

    FOR [Date]

    IN ([1/7/2009], [1/9/2009], [1/11/2009], [1/13/2009], [1/15/2009])

    ) As pvt

    I have one other column MediaBuyer which I cannot find a way to nest that inside here.

  • You're almos there.....

    SELECT MediaBuyer,

    [1/7/2009],

    [1/9/2009],

    [1/11/2009],

    [1/13/2009],

    [1/15/2009]

    FROM (

    SELECT [Date],

    [Count],

    MediaBuyer

    FROM #t

    ) p

    PIVOT (

    SUM([Count])

    FOR [Date] IN ([1/7/2009], [1/9/2009], [1/11/2009], [1/13/2009], [1/15/2009])

    ) As pvt

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Thanks John! I found an article on codeproject which helped me a lot. But thanks for your help too.

    http://www.codeproject.com/KB/database/Pivot2Columns.aspx

    Sid

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

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