Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


PIVOT more than two columns


PIVOT more than two columns

Author
Message
phani.gamini
phani.gamini
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 0
I have data as below in a table         
         
Region   Transactions   Production   Value
EAST   Sales    LUX    1000
EAST   Sales    Cinthol   1500
EAST   Purchases    LUX    1000
EAST   Purchases    Cinthol   1500
NORTH   Sales    LUX    3000
NORTH   Sales    Cinthol   3500
NORTH   Purchases LUX    3000
NORTH   Purchases    Cinthol   3500
SOUTH   Sales    LUX   4000
SOUTH   Sales    Cinthol    4500
SOUTH   Purchases    LUX    4000
SOUTH   Purchases    Cinthol    4500
WEST   Sales    LUX   2000
WEST   Sales    Cinthol    2500
WEST   Purchases    LUX    2000
WEST   Purchases    Cinthol   2500


I want a query to get the data as below.            
                  
          LUX       CINTHOL   
      Region   SALES   PURCHASES   SALES   PURCHASES
      EAST   1000   1000    1500   1500
      WEST   2000   2000    2500   2500
      NORTH   3000   3000    3500   3500
      SOUTH   4000   4000    4500   4500
Luis Cazares
Luis Cazares
SSCrazy Eights
SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)SSCrazy Eights (8.5K reputation)

Group: General Forum Members
Points: 8488 Visits: 18099
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search