View previous topic :: View next topic
|
Author |
Message |
Sumeendar
New User
Joined: 31 Jan 2006 Posts: 39
|
|
|
|
Hi All,
When we try to sort (DB2 SQL query) an alphamueric field which contains numeric and alphabets as values using ORDER BY clause (ascending order), does numeric values comes first OR Alphabets come first, after the sort....
Let me know
Thanks in advance |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Well, why don't try it out?
If a column COL1 'has these values':
Code: |
1001
1002
AA9999
AB8965
|
when ORDER by COL1 is performed, the output should be:
Code: |
AB8965
AA9999
1001
1002 |
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
The sequence of the ORDERed data depends on the collating sequence being used.
One of the more frustrating things learned is that these values sort differently in different environments - and it is Not wrong. . . It is usually, however, not what one wants. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
That's a valid point Dick. However, unless stated I'll assume it's about DB2 for zOS and the benefit of doubt goes to the batsman! (Okay, a phrase from a cricket-playing-country) |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
DB2 for z/OS used to be (almost) EBCDIC only : A-Z0-9
but since DB2 V8 UNICODE is catching up : 0-9A-Z
So actually it is not only different environment, but even different tables order differently. |
|
Back to top |
|
|
|