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 

DB2 Query To Change the order of rows

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


Joined: 20 Jul 2007
Posts: 2
Topics: 2

PostPosted: Thu Jan 06, 2011 8:42 am    Post subject: DB2 Query To Change the order of rows Reply with quote

1) I have a table ABCD where, when I give select, I get the following output
Code:

  RECTY
  ======
  A0100
  A0101
  A0102
  A0103
  A0104
  Z0105
  Z0106
  B0107
  B0108
  B0109
  B0110

We need the output to be in the order of
Code:

  Z0105
  Z0106
  A0100
  A0101
  A0102
  A0103
  A0104
  B0107
  B0108
  B0109
  B0110
 

Please provide a select statement which would result in the above output.

Canyou please help me.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Jan 06, 2011 11:57 am    Post subject: Reply with quote

manasa paduru,


Please post your queries to the right section. DB2 questions should be posted in DATABASE section. If these questions are part of interview then please post the questions in the Interview Q & A forum at the bottom.

Untested SQL

Code:

SELECT RECTY                                   
  FROM ABCD
 ORDER BY CASE WHEN SUBSTR(RECTY,1,1) = 'Z'   
               THEN ' ' || SUBSTR(RECTY,2,4)   
               ELSE RECTY END                 
               ;               


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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