sql server - ORDER BY DATE showing NULLS first then most recent dates -
I have a stored procedure that executes a selection statement I would like to order my results according to a date field and With all records, I would like to display all the records first and then the most recent dates.
The statement looks like:
SELECT A, B, C, [date of submission] by some visual order [date of submission] ASC Now it will display all records with all records, but when I get the rows values in them, they are not the most recent date in the scene.
If I replace ASC with DESC, then I get the dates in that order which I want but zero values are below. My result is set.
Is there a way to structate my query, so that I can display zero values at the top and then when the date is the value, order it down (oldest oldest) to descend?
@ Chris, you have it almost.
Order by (case WHEN [submission date] is zero, then 1 ELSE 0 END) DESC, [present date] DESC [Edit: #Apple asked me to show the above code to be shown at present]
I prefer it better than personally making "magic number" Magic number is always a problem in doing so.
Comments
Post a Comment