Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Simple order by question

Author  Topic 

dani2
Starting Member

32 Posts

Posted - 2008-09-22 : 03:55:34
Hi
I do select from a table ordered by a column which contains null value.
How can I get the sorting ascending but the lines with null values at the end?

thank you

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-22 : 03:58:11
try

order by case when col is null then 1 else 0 end, col

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-22 : 04:03:06
quote:
Originally posted by dani2

Hi
I do select from a table ordered by a column which contains null value.
How can I get the sorting ascending but the lines with null values at the end?

thank you


order by coalesce(column,'zzzzzzz')


if column is of character type.

order by coalesce(column,2147483647)

if integer

Go to Top of Page
   

- Advertisement -