views:

61

answers:

3

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

+1  A: 

add a dummy newcolumn = (length(targetcolumn)>0), and sort by this first.

BarsMonster
+3  A: 

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
Andomar
+2  A: 

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

AlexKuznetsov
+1 I believe this is the only answer so far that *really* adresses the question. OP asks specificly about the *default* sort order (which doesn't exist)
Lieven
I suspect this isn't what they mean though. They would like to be able to do `order by x` and have nulls and empty strings at the end rather than the beginning.
Martin Smith
@Martin : I can confirm you are correct : that that is eaxctly what they mean. Maybe its the collation sequence I need to change.
cindi