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 

Ordering a specific coloumn based on the values i specify

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


Joined: 30 Aug 2006
Posts: 32
Topics: 15
Location: Chennai

PostPosted: Sat Nov 25, 2006 5:13 am    Post subject: Ordering a specific coloumn based on the values i specify Reply with quote

I have a particular coloumn in my table named "STATUS" . This is a numeric field with values ranging as 10,20,30,40,50.

I donot want this coloumn either in ascending or descending order.
I want it in the following order ( 30, 10, 50, 20, 40). How shall i specify it in my order by clause?
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Sat Nov 25, 2006 6:53 am    Post subject: Reply with quote

you can use a CASE to set another selected column/:Host-variable based on your STATUS and ORDER BY the CASEd column.

or

using case, change the status from 30 to 'A 30', 10 to 'B 10' etc...
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
Catherine
Beginner


Joined: 30 Aug 2006
Posts: 32
Topics: 15
Location: Chennai

PostPosted: Sat Nov 25, 2006 7:02 am    Post subject: Reply with quote

Dick,

thks a lot dick!! Could You Plz post the exact Case syntax i should give in the order by clause . I get an error while executing the query
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Sat Nov 25, 2006 8:51 am    Post subject: Reply with quote

Catherine,

Try this untested sql

Code:

SELECT Z.STATUS                         
  FROM (SELECT STATUS                   
              ,CASE STATUS               
                    WHEN 30 THEN 1       
                    WHEN 10 THEN 2       
                    WHEN 50 THEN 3       
                    WHEN 20 THEN 4       
                    WHEN 40 THEN 5       
                    ELSE 9 END  AS SR_NO
         FROM Table) Z                     
 ORDER BY SR_NO                         
 ;     


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Catherine
Beginner


Joined: 30 Aug 2006
Posts: 32
Topics: 15
Location: Chennai

PostPosted: Tue Nov 28, 2006 5:43 am    Post subject: Reply with quote

Thks Kolusu.. I got it!!!
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