Putting rows into columns?? Help

  • I would like to write a query that transposes the rows as columns such as below:

    Changes this:

    InvNo Product Amount

    1003   Apple    10 

    1003   Orange   20 

    1003   Banana    5 

    1004   Apple     4 

    1004   Orange    3 

    1005   Orange    4 

       

    and presents it like this:

    InvNo Apple Orange Banana

    1003   10     20     5

    1004    4      3     0

    1005    0      4     0

    Thanks


    Fardin Golzar

  • This is an example of a "Pivot". Search on keyword "pivot" and you'll find many examples like this:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=9&messageid=159163

     

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

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