Over a million developers have joined DZone.

Pull Date-Effective Records That Intersect A Given Range

Basics of how to pull records that intersect a date range from a temporal (aka date-effective) database.

-- @rangeStart is the start of the date range of interest
-- @rangeEnd is the end of the date range of interest
-- If you use null to signify infinity, then use the commented line instead of the one above it.
-- Assumes both intervals are [Start, End), ie, start is inclusive, end is exclusive.
select *
from DateEffectiveTable
where StartDate < @rangeEnd
  and EndDate > @rangeStart
  -- and coalesce(endDate, '9999-12-31') > @rangeStart

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}