Nearest max date before a specified one

  • Thread starter Thread starter Duane Hookom
  • Start date Start date
D

Duane Hookom

SELECT Top 1 dEntryDate
FROM R tblDates
WHERE dEntryDate<CDate('1.1.2005')
ORDER BY dEntryDate Desc;
 
Hi,

I am trying to create an SQL statement which would return to me the maximum
date before a specified date. I was able to get a list of records with dates
prior to the one I enter but not the last one. Can anyone help? Thanks.

SELECT tblDates.dEntryDate
FROM R tblDates
WHERE (((tblDates.dEntryDate)<CDate('1.1.2005')));

Frank
 
SELECT Max(tblDates.dEntryDate) as MaxDate
FROM R tblDates
WHERE (((tblDates.dEntryDate)<CDate('1.1.2005')));
 
Hi,

Thank you for the responses. I have noticed in both responses the letter "R"
after word FROM. What does this do? Thanks.

Frank
 
Well I thought it was strange to see the R there. It would be valid syntax if
you had a table named "R" but wished to refer to the table in the query as
"tblDates". Normally, you would probably do that the other way round - a table
named tblDates that you wanted to refer to as R to cut down on typing or as a
second instance of the same table in some self-referencing schemes.
 
Back
Top