PIVOT more than two columns

  • I have data as below in a table

    RegionTransactionsProductionValue

    EASTSales LUX 1000

    EASTSales Cinthol1500

    EASTPurchases LUX 1000

    EASTPurchases Cinthol1500

    NORTHSales LUX 3000

    NORTHSales Cinthol3500

    NORTHPurchases LUX 3000

    NORTHPurchases Cinthol3500

    SOUTHSales LUX4000

    SOUTHSales Cinthol 4500

    SOUTHPurchases LUX 4000

    SOUTHPurchases Cinthol 4500

    WESTSales LUX2000

    WESTSales Cinthol 2500

    WESTPurchases LUX 2000

    WESTPurchases Cinthol2500

    I want a query to get the data as below.

    LUX CINTHOL

    RegionSALESPURCHASESSALESPURCHASES

    EAST10001000 15001500

    WEST20002000 25002500

    NORTH30003000 35003500

    SOUTH40004000 45004500

  • You could easily use CROSS TABS to pivot your data.

    Read the following article and come back if you need extra help. 😉

    http://www.sqlservercentral.com/articles/T-SQL/63681/

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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