I'm using Access in Office 10 in a mixed Windows 7 / Windows XP environment.
I need to be able to select the current address for employees from a list. The problem I have is that the address datefrom
could be past, future or null.
Removing future is obviously easy in the criteria, i.e. WHERE datefrom <=date()
The problem I have is that in the initial import of address data, most addresses did not have this information, and so the field is null. An example of the data is below: (date format is dd/mm/yyyy
)
ID EmployeeID Postcode DateFrom
1 1 AB12 3CD [null]
2 2 GH12 5RF [null]
3 1 CD34 5EF 10/03/2012
4 3 HA25 3PO [null]
5 3 HA4 7RT 04/06/2012]
6 3 DB43 5YU 12/11/2011]
My desired output would be: (order of employees not important)
ID EmployeeID Postcode DateFrom
2 2 GH12 5RF [null]
3 1 CD34 5EF 10/03/2012
5 3 HA4 7RT 04/06/2012
I've tried sorting by DateFrom DESC
which does order the list as below:
ID EmployeeID Postcode DateFrom
3 1 CD34 5EF 10/03/2012
1 1 AB12 3CD [null]
2 2 GH12 5RF [null]
5 3 HA4 7RT 04/06/2012
6 3 DB43 5YU 12/11/2011
4 3 HA25 3PO [null]
So if I could then just take the first result for each employee I'd be fine. However I've tried (and failed) to do SQL including things like DISTINCT
, first()
and GROUP BY
, but don't seem to be able to get anywhere.
I probably just can't see the easy obvious answer, so any help would be very much appreciated.