Reputation: 105
I have a list of records like so
ID---EffectiveDate---Rate
1----1/1/2011--------1.2
2----1/1/2012--------1.3
3----1/1/2013--------1.5
4----1/1/2014--------1.2
Given a date parameter, d1, I want to get the record with the latest effective date prior to d1. So, if d1 = 6/1/2012, I want to get the second record. How can I write a query like this in MS Access SQL?
Upvotes: 0
Views: 1121
Reputation: 102
Try this,
select top 1 * from tablename where EffectiveDate<=d1 order by EffectiveDate desc
Upvotes: 1
Reputation: 1262
I think the SQL query would looks something like this, based on your data:
SELECT TOP 1 EffectiveDate
FROM MyTableOfDates
WHERE EffectiveDate <= #MyInputDate#
ORDER BY EffectiveDate DESC
Upvotes: 1