I am getting unwanted duplicate rows in my result set, so I added the
DISTINCT keyword to my outermost SELECT. My working query then returned
the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2
Message: An expression in the ORDER BY clause in the following
position, or starting with "CASE..." in the "ORDER BY" clause is not
valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098,
SQLERRMC: 2;-214;42822;CASE. ..|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE
WHEN t01.lot_numb IS NULL AND
t01.lot_suffix IS NOT NULL
THEN 0
ELSE t01.lot_numb
END,
COALESCE(t01.lo t_suffix, ''),
animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The
clause works when there is no DISTINCT.
DISTINCT keyword to my outermost SELECT. My working query then returned
the following message:
DB2 SQL error: SQLCODE: -214, SQLSTATE: 42822, SQLERRMC: CASE...;ORDER BY;2
Message: An expression in the ORDER BY clause in the following
position, or starting with "CASE..." in the "ORDER BY" clause is not
valid. Reason code = "2".
More exceptions ... DB2 SQL error: SQLCODE: -727, SQLSTATE: 56098,
SQLERRMC: 2;-214;42822;CASE. ..|ORDER BY|2
The ORDER BY clause is below:
ORDER BY CASE
WHEN t01.lot_numb IS NULL AND
t01.lot_suffix IS NOT NULL
THEN 0
ELSE t01.lot_numb
END,
COALESCE(t01.lo t_suffix, ''),
animal_id
I didn't include the whole query because of its length.
My problem is that I don't understand DISTINCT's effect on ORDER BY. The
clause works when there is no DISTINCT.
Comment