MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ORDER BY non-alphetical order

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Tue Oct 30, 2007 4:03 pm    Post subject: ORDER BY non-alphetical order Reply with quote

I would like to retrieve the rows in a specific order of the values of a given column.

column1 will only contain one of the below given values, at any time:
AA,YY,RR,BB,KK.

I would like to retrieve the rows in the order of RR, YY, BB, AA, KK. Is it possible to retrieve in this specific oeder other than alphebetic order?
_________________
Thanks
Back to top
View user's profile Send private message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Wed Oct 31, 2007 8:16 am    Post subject: Reply with quote

Code:

SELECT
  CASE COL1
     WHEN 'RR' THEN 1
     WHEN 'YY' THEN 2
     WHEN 'BB' THEN 3
     WHEN 'AA' THEN 4
     ELSE  5
   END AS DUMMY,
   COL1, COL2, ......
ORDER BY DUMMY
Back to top
View user's profile Send private message
Bill Dennis
Advanced


Joined: 03 Dec 2002
Posts: 579
Topics: 1
Location: Iowa, USA

PostPosted: Wed Oct 31, 2007 1:17 pm    Post subject: Reply with quote

Very Happy A shining example of why I love the knowledgeable users at this site.
_________________
Regards,
Bill Dennis

Disclaimer: My comments on this foorum are my own and do not represent the opinions or suggestions of any other person or business entity.
Back to top
View user's profile Send private message
Sarangadhar
Beginner


Joined: 14 Oct 2004
Posts: 130
Topics: 43
Location: virtual village

PostPosted: Thu Nov 01, 2007 6:00 pm    Post subject: Reply with quote

Thanks danm. nice one.
_________________
Thanks
Back to top
View user's profile Send private message
acevedo
Beginner


Joined: 03 Dec 2002
Posts: 127
Topics: 0
Location: Europe

PostPosted: Fri Nov 02, 2007 2:13 am    Post subject: Reply with quote

BTW, you don't need to give the DUMMY name, I mean:

Code:

SELECT
  CASE COL1
     WHEN 'RR' THEN 1
     WHEN 'YY' THEN 2
     WHEN 'BB' THEN 3
     WHEN 'AA' THEN 4
     ELSE  5
   END
  ,COL1,
  ,COL2......
ORDER BY 1
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group