Finding rows that intersect with a date period
- by DavidWimbush
This one is mainly a personal reminder but I hope it helps somebody else too. Let's say you have a table that covers something like currency exchange rates with columns for the start and end dates of the period each rate was applicable. Now you need to list the rates that applied during the year 2009. For some reason this always fazes me and I have to work it out with a diagram. So here's the recipe so I never have to do that again:
select *
from ExchangeRate
where StartDate < '31-DEC-2009'
and EndDate > '01-JAN-2009'
That is all!