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 a DB2 varchar column - 1st char being different

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


Joined: 22 Jun 2005
Posts: 41
Topics: 14

PostPosted: Mon Oct 17, 2011 8:59 pm    Post subject: ORDER BY a DB2 varchar column - 1st char being different Reply with quote

The first character of a DB2 table varchar column can be a special character/Numeric/Alphabet. How can I perform an ORDER BY so that the result contains all special characters first, then numeric and then alphabet.
Example: Values of a column include
Code:

<test1
@test2 column
Abb char
Bcc char
1test char
2test space


Results are required as
Code:

<test1
@test2 column
1test char
2test space
Abb char
Bcc char
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Mon Oct 17, 2011 10:48 pm    Post subject: Reply with quote

Suggest you reconsider what you want if this is to be used on the mainframe.

If you get the values in the sequence you say you want, they will be pretty much useless when used to compare against each other or other "normal"ly sequenced data. The data will NOT be in the system collating sequence. . .

Why does someone believe this "sequence" will be useful?
_________________
All the best,

di
Back to top
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Tue Oct 18, 2011 4:15 am    Post subject: Reply with quote

Code:
order by position(substr(col1,1,1),'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',octets), substr(col1,2)
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Oct 18, 2011 10:42 am    Post subject: Reply with quote

thx GuyC,

another keeper. much easier than figuring it out on my own.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
GuyC
Supermod


Joined: 27 May 2011
Posts: 35
Topics: 0

PostPosted: Wed Oct 19, 2011 3:41 am    Post subject: Reply with quote

dbzTHEdinosauer wrote:
thx GuyC,

another keeper. much easier than figuring it out on my own.

you're welcome.
It's just another implementation for 'user defined sortsequence'
I do like this one :
Code:
order by position(substr(col1,1,3),'MonTueWedThuFriSatSun',octets)


Ps.: I didn't invent this, I've read it somewhere (and remembered).
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