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

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -