dbTalk Databases Forums  

Null Date Values and order by

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Null Date Values and order by in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dean Mathews
 
Posts: n/a

Default Null Date Values and order by - 07-24-2003 , 06:18 PM






How do I order a query by a date field ASC, but have any NULL values
show up last? i.e.

7/1/2003
7/5/2003
7/10/2003
<NULL>
<NULL>


Any help will greatly be appreciated

Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Null Date Values and order by - 07-25-2003 , 02:21 AM






Dean Mathews (paradigmis (AT) hotmail (DOT) com) writes:
Quote:
How do I order a query by a date field ASC, but have any NULL values
show up last? i.e.

7/1/2003
7/5/2003
7/10/2003
NULL
NULL
ORDER BY colaesce(date, '99991231')

--
Erland Sommarskog, SQL Server MVP, sommar (AT) algonet (DOT) se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Reply With Quote
  #3  
Old   
Andre Kuyt
 
Posts: n/a

Default Re: Null Date Values and order by - 07-25-2003 , 04:25 AM



paradigmis (AT) hotmail (DOT) com (Dean Mathews) wrote in message news:<e32dbacc.0307240715.56279933 (AT) posting (DOT) google.com>...
Quote:
How do I order a query by a date field ASC, but have any NULL values
show up last? i.e.

7/1/2003
7/5/2003
7/10/2003
NULL
NULL


Any help will greatly be appreciated
simply use the following in the ORDER BY Clause
select
datefield
from
table
ORDER BY
ISNULL(datefield, '20550101')

(or any other date far larger than the maximum of your resultset)


Reply With Quote
  #4  
Old   
Dean Mathews
 
Posts: n/a

Default Re: Null Date Values and order by - 07-28-2003 , 08:18 AM



This works great, thanks for all your help

Dean

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.