473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Strange sort result on DB2 LUW v8.1.9

Please explain tome why the third row of my result is not the fourth
row. In most Western alphabets 'dd'>'c'.
>[SQL] Script lines: 1-29 ---------------------------
SELECT t1.*,
lot_numb, lot_suffix, part_of_lot_numb, part_of_lot_suffix,
CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS NULL)
THEN COALESCE(lot_numb, 0)
ELSE COALESCE(part_of_lot_numb, 0)
END,
CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS NULL)
THEN COALESCE(lot_suffix, '')
ELSE COALESCE(part_of_lot_suffix, '')
END,
COALESCE(lot_numb, 0), COALESCE(lot_suffix, ''),
COALESCE(RTRIM(LTRIM(CHAR(t2.lot_numb))), '') ||
COALESCE(t2.lot_suffix, '') AS lot,
t3.namex,
CHAR(t3.birth_date) AS birth_datep,
t3.sex
FROM is3.auction_done_bids t1
JOIN is3.auction_items t2 ON t2.item_id=t1.item_id
JOIN is3.animals t3 ON t3.bhid=t2.bhid
WHERE t1.auction_id=21 AND t1.invoice_no=2
ORDER BY CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS
NULL)
THEN COALESCE(lot_numb, 0)
ELSE COALESCE(part_of_lot_numb, 0)
END,
CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS
NULL)
THEN COALESCE(lot_suffix, '')
ELSE COALESCE(part_of_lot_suffix, '')
END,
COALESCE(lot_numb, 0), COALESCE(part_of_lot_suffix, '')
FOR READ ONLY 

AUCTION_ID BIDDER_ID ITEM_ID AMOUNT WHEN_BID
INVOICE_NO LOT_NUMB LOT_SUFFIX PART_OF_LOT_NUMB
PART_OF_LOT_SUFFIX 11 12 13 14 LOT NAMEX
BIRTH_DATEP SEX
------------- ------------ ---------- ---------
-------------------- ------------- ----------- -------------
------------------- --------------------- ----- ----- ----- -----
------ ------------------------------ -------------- ------
21 1 25 334 8/10/2006 6:35:15
PM 2 1 (null) (null)
(null) 1 1 1 NAME OF THIS
ANIMAL IS AAA8AAA 2005-11-01 C

21 1 23 333 8/10/2006 6:35:15
PM 2 1 a 1
(null) 1 1 a 1a (null)
(null) B

21 1 24 0 8/10/2006 6:35:15
PM 2 1 dd 1
(null) 1 1 dd 1dd (null)
2005-11-07 (null)

21 1 26 333 8/10/2006 6:35:15
PM 2 1 c 1
(null) 1 1 c 1c (null)
2000-11-01 C

4 record(s) selected [Fetch MetaData: 0/ms] [Fetch Data: 78/ms]

[Executed: 8/11/06 2:40:08 AM GMT ] [Execution: 172/ms]
Aug 11 '06 #1
1 1438

Bob Stearns wrote:
Please explain tome why the third row of my result is not the fourth
row. In most Western alphabets 'dd'>'c'.
>[SQL] Script lines: 1-29 ---------------------------
SELECT t1.*,
lot_numb, lot_suffix, part_of_lot_numb, part_of_lot_suffix,
CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS NULL)
THEN COALESCE(lot_numb, 0)
ELSE COALESCE(part_of_lot_numb, 0)
END,
CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS NULL)
THEN COALESCE(lot_suffix, '')
ELSE COALESCE(part_of_lot_suffix, '')
END,
COALESCE(lot_numb, 0), COALESCE(lot_suffix, ''),
COALESCE(RTRIM(LTRIM(CHAR(t2.lot_numb))), '') ||
COALESCE(t2.lot_suffix, '') AS lot,
t3.namex,
CHAR(t3.birth_date) AS birth_datep,
t3.sex
FROM is3.auction_done_bids t1
JOIN is3.auction_items t2 ON t2.item_id=t1.item_id
JOIN is3.animals t3 ON t3.bhid=t2.bhid
WHERE t1.auction_id=21 AND t1.invoice_no=2
ORDER BY CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS
NULL)
THEN COALESCE(lot_numb, 0)
ELSE COALESCE(part_of_lot_numb, 0)
END,
CASE WHEN(part_of_lot_numb IS NULL AND part_of_lot_suffix IS
NULL)
THEN COALESCE(lot_suffix, '')
ELSE COALESCE(part_of_lot_suffix, '')
END,
COALESCE(lot_numb, 0), COALESCE(part_of_lot_suffix, '')
FOR READ ONLY 

AUCTION_ID BIDDER_ID ITEM_ID AMOUNT WHEN_BID
INVOICE_NO LOT_NUMB LOT_SUFFIX PART_OF_LOT_NUMB
PART_OF_LOT_SUFFIX 11 12 13 14 LOT NAMEX
BIRTH_DATEP SEX
------------- ------------ ---------- ---------
-------------------- ------------- ----------- -------------
------------------- --------------------- ----- ----- ----- -----
------ ------------------------------ -------------- ------
21 1 25 334 8/10/2006 6:35:15
PM 2 1 (null) (null)
(null) 1 1 1 NAME OF THIS
ANIMAL IS AAA8AAA 2005-11-01 C

21 1 23 333 8/10/2006 6:35:15
PM 2 1 a 1
(null) 1 1 a 1a (null)
(null) B

21 1 24 0 8/10/2006 6:35:15
PM 2 1 dd 1
(null) 1 1 dd 1dd (null)
2005-11-07 (null)

21 1 26 333 8/10/2006 6:35:15
PM 2 1 c 1
(null) 1 1 c 1c (null)
2000-11-01 C

4 record(s) selected [Fetch MetaData: 0/ms] [Fetch Data: 78/ms]

[Executed: 8/11/06 2:40:08 AM GMT ] [Execution: 172/ms]
In 2nd to 4th result rows, both of Expression1 and Expression2 of
ORDER BY were not satisfy WHEN condition(in those rows part_of_lot_numb
IS NOT NULL).
So, it is equivalent to
ORDER BY COALESCE(part_of_lot_numb, 0), COALESCE(part_of_lot_suffix,
''),
COALESCE(lot_numb, 0), COALESCE(part_of_lot_suffix, '')

Aug 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Carlos Ribeiro | last post by:
Hello all. I'm sending this to the list because I would like to know if someone else has ever stumbled across this one, and also because one possible solution is to patch, or simply "decorate",...
15
by: Mike Fellows | last post by:
im running the code below when a new item is selected within a combobox the code runs fine but when it gets to me.close it crashes - it doesnt start the next form just crashes (its not debugabble)...
3
by: 99m | last post by:
I used to have Apache and PHP4 working perfectly in Ubuntu Hoary Linux. I upgraded to Ubuntu Breezy Linux and I either get one of the following problems: "You don't have permission to access...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
11
by: Martin Joergensen | last post by:
Hi, I've encountered a really, *really*, REALLY strange error :-) I have a for-loop and after 8 runs I get strange results...... I mean: A really strange result.... I'm calculating...
20
by: SpreadTooThin | last post by:
I have a list and I need to do a custom sort on it... for example: a = #Although not necessarily in order def cmp(i,j): #to be defined in this thread. a.sort(cmp) print a
7
by: abracadabra | last post by:
I am reading an old book - Programming Pearls 2nd edition recently. It says, "Even though the general C++ program uses 50 times the memory and CPU time of the specialized C program, it requires...
9
by: Aaron Watters | last post by:
....is to forget they are sorted??? While trying to optimize some NUCULAR libraries I discovered that the best way to merge 2 sorted lists together into a new sorted list is to just append them...
6
by: lukasso | last post by:
Hi, this is my code that should produce something like a timetable for a few days with each day divided into 30 minute pieces. It makes query from MySQL and then creates a 2d $array which then is to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.