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 2000 Forums
 Transact-SQL (2000)
 Sorting Dates with Null values, Order of

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-04-26 : 09:42:39
Chad writes "I have a table filled with tasks. Each task has a due date. I would like to sort these tasks by due date, such that any non-null dates are sorted first, followed by due dates with a null value. By default, SQL server returns null values first, then actual dates.

The work around I'm using is to use the isnull function and replace null dates with 1/1/9999 to get these to sort AFTER the non-null date values. This works fine technically, but is confusing the users...

Any other ideas?

Thanks,
Chad

SQL Server 2000"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2006-04-26 : 09:43:27
SELECT * FROM myTable
ORDER BY
CASE WHEN DueDate IS NULL THEN 1 ELSE 0 END,
DueDate
Go to Top of Page
   

- Advertisement -