Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4577496
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:21:14+00:00 2026-05-21T20:21:14+00:00

I am trying to order by date. I want the most recent dates coming

  • 0

I am trying to order by date. I want the most recent dates coming in first. That’s easy enough, but there are many records that are null and those come before any records that have a date.

I have tried a few things with no success:

ORDER BY ISNULL(Next_Contact_Date, 0)

ORDER BY ISNULL(Next_Contact_Date, 999999999)

ORDER BY coalesce(Next_Contact_Date, 99/99/9999)

How can I order by date and have the nulls come in last? The data type is smalldatetime.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:21:14+00:00Added an answer on May 21, 2026 at 8:21 pm

    smalldatetime has range up to June 6, 2079 so you can use

    ORDER BY ISNULL(Next_Contact_Date, '2079-06-05T23:59:00')
    

    If no legitimate records will have that date.

    If this is not an assumption you fancy relying on a more robust option is sorting on two columns.

    ORDER BY CASE WHEN Next_Contact_Date IS NULL THEN 1 ELSE 0 END, Next_Contact_Date
    

    Both of the above suggestions are not able to use an index to avoid a sort however and give similar looking plans.

    enter image description here

    One other possibility if such an index exists is

    SELECT 1 AS Grp, Next_Contact_Date 
    FROM T 
    WHERE Next_Contact_Date IS NOT NULL
    UNION ALL
    SELECT 2 AS Grp, Next_Contact_Date 
    FROM T 
    WHERE Next_Contact_Date IS NULL
    ORDER BY Grp, Next_Contact_Date
    

    Plan

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a higher-order Racket function that takes a first-order function
I have rows in a table that I need to order by date. Easy
I'm trying to order some dates so that they are listed in a particular
I am trying to order a database by date but I am having trouble
I'm trying to order models in a Django app using a field that has
I was trying to create a linear order from git log output, but all
this is my first app and i need to be using dates i want
I'm trying to SELECT from two tables and ORDER BY date (a column they
I'm trying to search for the most recent occurrences of a bunch of transactions
I'm trying order a Linq to NHibernate query by the sum of it's children.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.