Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select record on with 1st date prior to current date

Status
Not open for further replies.

werosen1

Programmer
Mar 30, 2006
16
US
Greetings:

I'm trying to figure out how to Select a record from an Access 2002 database with SQL by identifying from the date field (rDate), the first date that exists prior to today's date.

Has anyone dealt with this that could steer me in the right direction?
 
Hi,

Would it be possible to select all records and set as criteria <> date()?

Then you could select the max date of these records:

Code:
SELECT First(MyTable.key) AS FirstOfkey, Max(MyTable.MyDateField) AS MaxOfMyDateField
FROM MyTable
HAVING (((Max(MyTable.MyDateField))<>Date()))

EasyIT
 
If you want to select the entire record, it would be something like:
Code:
select *
from MyTable a
where rDate<Date()
  and not exists (
    select 1
    from MyTable b
    where b.rDate<Date()
      and b.rDate>=a.rDate
      and b.Key>a.Key)
Where the field Key is any field you want to use as a tie breaker since multiple records may exist with the same date.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top