Looking up a Rate change table

  • Thread starter Thread starter Ian Chappel
  • Start date Start date
I

Ian Chappel

Say I have tblRates with the fields FromDate and NewRate.

What's the easiest way to obtain the Rate on a particular day, which could
be between two FromDates or >MaxOfFromDate? I'd rather not have a ToDate
field.

This could take the form of a query, or a DLookup.
 
To use a query, it will be much easier to implement, if you have the end
date. Otherwise, you have to find the next date in the series, then react.
It just adds an extra step to the code, whereas it takes two seconds to
enter.
 
Ian said:
Say I have tblRates with the fields FromDate and NewRate.

What's the easiest way to obtain the Rate on a particular day, which could
be between two FromDates or >MaxOfFromDate? I'd rather not have a ToDate
field.

This could take the form of a query, or a DLookup.


You did not state the context where you want to do this, but
this kind of query should get you started:

SELECT TOP 1 NewRate
FROM tblRates
WHERE FromDate <= anydatevalue
ORDER BY FromDate DESC
 
Thanks Marsh, that's just what I wanted. I don't like the idea of inputting
a ToDate, as it seems unnecessary, and overlapping periods could be created
unless data is carefully validated.

I'm not sure why the first reply felt there should be a ToDate?
 
I haven't checked lately, but I think TOP is not a standard
ANSI SQL predicate. Without TOP this can be a rather messy
thing to do and it's often not worth the effort if you need
to use a query that's portable to other database engines,
which may very well be Steve's point of view.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top