Can I change the default sort order in a SQL server database so that nulls and zero length strings are displayed last.
Its SQL Server 2000
I stress, I want to change the default order for all queries, if possible
Can I change the default sort order in a SQL server database so that nulls and zero length strings are displayed last.
Its SQL Server 2000
I stress, I want to change the default order for all queries, if possible
add a dummy newcolumn = (length(targetcolumn)>0), and sort by this first.
You can do almost any sort using a case
in an order by
. Here's the null
columns first, then the empty strings, and the rest ordered on col1 and col3:
select *
from YourTable
order by
case when col1 is null then 1
when col1 = '' then 2
else 3
end
, col2
, col3 desc
No you cannot do that: Without ORDER BY, there is no default sort order. This is a very common question, so I wrote a canned answer: Without ORDER BY, there is no default sort order