View Full Version : Sort Order Question


Brando
11-03-2006, 10:09 AM
Is there a way to sort dates using "Decending" but have blank dates stay on top?

I have a listbox based on a qurery that displays all pending and completed jobs. The query sorts (Ascending) the "Job Complete" date. This conveniently puts all of the pending jobs with null values at the top of the list. The bad part is that this puts recently completed jobs at the very bottom of a (thankfully) long list. Is there a way around this?
Thank you!

ByteMyzer
11-03-2006, 10:17 AM
In the select statement for listbox's RowSource, use the following ORDER BY clause:

ORDER BY IsNull([Job Complete]), [Job Complete] DESC

Brando
11-03-2006, 10:37 AM
The RowSource has the name of the query. So where is the "select statement for the listbox's RowSource" located?

I tried putting that code in the Order By of the properties of the query, but it had no effect.

ByteMyzer
11-03-2006, 12:17 PM
Placing this order by clause in the Query's OrderBy property will only affect how the query sorts the data when the query itself is being viewed. You need to open the query in SQL View and place the ORDER BY clause at the end of the query, before the semicolon.

For example, if your query reads something like:

SELECT *
FROM MyTable;

...you would change it to:

SELECT *
FROM MyTable
ORDER BY IsNull([Job Complete]), [Job Complete] DESC;

Brianwarnock
11-03-2006, 12:19 PM
The simple way to achieve this is to do a normal grid query with sort descending on the field, then switch to sql view and replace the orderby clause with the one suggested by ByteMyzer,

brian

OOPs ByteMyzer is a quicker typist

Brando
11-03-2006, 01:56 PM
Thank you sooo much! It worked exactly as you said it would. This has been a thorn in my side for too long. I will definitely 'pay it forward'.

Brando