Finding rows that intersect with a date period

Posted by DavidWimbush on SQL Blogcasts See other posts from SQL Blogcasts or by DavidWimbush
Published on Tue, 09 Mar 2010 19:40:00 GMT Indexed on 2010/03/11 17:20 UTC
Read the original article Hit count: 430

Filed under:

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!

© SQL Blogcasts or respective owner

Related posts about Tips and Tricks