October 31st, 2012, 01:27 AM
Generate CASE WHEN Query with ORDER BY involving Secondary Sort
Below Query I understand is improper wrt syntax. Need to modify query to fetch correct result for me. Please help!
select * from tableA order by
case when a is not null then
b DESC, c DESC END
Note: DESC or ASC is dynamic coming from java-code.
October 31st, 2012, 01:48 AM
Try it like this:
order by case when a is not null then 'a desc'
else 'b desc, c desc'
October 31st, 2012, 02:35 AM
Thanks but not giving correct result.
This query is sytactically correct but NOT giving correct sorted result.
October 31st, 2012, 04:40 AM
If that is not result you desire, you need to supply more details of how you want your data to be ordered.
by case when a is not null then a
else b end desc,