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 > Oracle SQL - Order BY question ??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-03, 11:01
jww12172 jww12172 is offline
Registered User
 
Join Date: Oct 2003
Location: miami
Posts: 2
Question Oracle SQL - Order BY question ??

This should be an easy one.
Scenario:
a column can contain 1 of 4 codes "R" "T" "C" "P"

with a one sql select statement how can I order first all "R"s, then "T"s, then "C"s, then "P"s.


when using sql to an Access DB the following Order by works:
ORDER BY
CSFOCP.FORM.TYPE = 'R',
CSFOCP.FORM.TYPE = 'T',
CSFOCP.FORM.TYPE = 'C',
CSFOCP.FORM.TYPE = 'P'


but it doesn't work in Oracle.

Thanks
jim
Reply With Quote
  #2 (permalink)  
Old 10-31-03, 16:04
cvandemaele cvandemaele is offline
Registered User
 
Join Date: Oct 2003
Location: Switzerland
Posts: 140
You might want to throw in a CASE statement

SELECT
YOUR_COLUMN,
CASE YOUR_COLUMN
WHEN 'R' THEN 1
WHEN 'T' THEN 2
WHEN 'C' THEN 3
WHEN 'P' THEN 4
ELSE 5
END AS SORT_ORDER
FROM YOUR_TABLE
ORDER BY 2
Reply With Quote
  #3 (permalink)  
Old 11-01-03, 11:45
jww12172 jww12172 is offline
Registered User
 
Join Date: Oct 2003
Location: miami
Posts: 2
Yes, that worked well. Thank you.
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