In SQL, I have used
...ORDER BY name DESC NULLS LAST
which works quite awesome, yet is there any way that I can set a specific value to be last? Such as an empty string (@EMPTY).
...ORDER BY name DESC (@EMPTY) LAST
I am dynamically building SQL off of user choices on a table, and when the user changes the sort order, I change my sort order in my SQL. Also, the user can choose which column to sort by. The column that I am sorting by will either be type text
or type int
. I don't need any fancy ORDER BY
when column
is type int
, but I do need to force all values of ""
to the end of the ORDER BY
when the type
of the column
is text
.
Thanks!
You can use a case
as the first element in the sort order:
order by
case when name = '' then 1 else 0 end
, name desc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With