I have a stored procedure which executes a select statement. I would like my results ordered by a date field and display all records with NULL dates first and then the most
I know this is old, but when I found it I noticed the accepted solution, https://stackoverflow.com/a/821856/7177892, could be simplified by making the result of the CASE statement be either today (GETDATE()) or the actual date.
Original:
ORDER BY (CASE WHEN [Submission Date] IS NULL THEN 1 ELSE 0 END) DESC,
[Submission Date] DESC
Simplified:
ORDER BY (CASE WHEN [Submission Date] IS NULL
THEN GETDATE()
ELSE [Submission Date]
END) DESC