I have a query as shown below which select a field named "DueDate" and then orders by "DueDate". This query is used to import data into Microsoft Excel, and due to the fact that Excel doesn't handle the Nz function correctly when importing data, I had to format the IIF statement as shown instead of just using an Nz function to reformat NULL values.
The problem is that using the IIF statement sorts the results incorrectly. For example...
My expected results are:
OrderID DueDate
1234 04/4/05
2345 04/5/05
3456 04/25/05
But the actual results are:
OrderID DueDate
3456 04/25/05
1234 04/4/05
2345 04/25/05
If I just select and sort by the "DueDate" field without formatting it with the IIF, it sorts correctly. But for some reason the IIF throws off the sort. How can this be fixed? Thanks!
--
Not until I became a Network Administrator did the error message "See your Network Administrator for assistance" become petrifying.
Code:
SELECT DISTINCT OrderID, IIf(IsNull([tblOrder.DueDate]),"No Date",([tblOrder.DueDate])) AS DueDate
FROM tblOrder
ORDER BY IIf(IsNull([tblOrder.DueDate]),"No Date",([tblOrder.DueDate]));
My expected results are:
OrderID DueDate
1234 04/4/05
2345 04/5/05
3456 04/25/05
But the actual results are:
OrderID DueDate
3456 04/25/05
1234 04/4/05
2345 04/25/05
If I just select and sort by the "DueDate" field without formatting it with the IIF, it sorts correctly. But for some reason the IIF throws off the sort. How can this be fixed? Thanks!
--
Not until I became a Network Administrator did the error message "See your Network Administrator for assistance" become petrifying.