If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > How to display rows as columns

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-06, 20:16
dsmbwoy dsmbwoy is offline
Registered User
 
Join Date: Nov 2005
Posts: 91
How to display rows as columns

Hi everyone. I need some help formating the output of my query. My query currently displays multiple charge items per trip in multiple rows. What I want to be able to do is display these rows in columns so that I only have one distinct row containing all the information. Please see below. Thanks in advance for everyones help.


Current results

Trip Charge Rate
-----------------------
123 Shipping 500.00
123 FSC 35.00
456 Shipping 750.00
456 FSC 45.00


I want to be able to display my output in columns

Trip Shipping_Charge FSC
----------------------------------
123 500.00 35.00
456 750 45.00
Reply With Quote
  #2 (permalink)  
Old 09-27-06, 21:39
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Normally I'm terribly suspicious of posts like this... This kind of question at this time of year is almost always homework. For some weird reason I can't identify, I'm willing to give you a straight answer.
Code:
SELECT trip
,  Sum(CASE WHEN 'Shipping' = Charge THEN rate END) AS Shipping_Charge
,  Sum(CASE WHEN 'FSC' = Charge THEN rate END) AS FSC
   GROUP BY Trip
-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On