Do you need maximum performance and are therefore ready to make changes to the circuit? Or is the number of records so small, and performance is relatively unimportant, what do you want a query that will work with data as is?
The easiest and fastest way to do this is to save the second field of birth data, but without the year. I put quotes around "without" because the date cannot actually be a year. So, instead, you just base it on another year.
Re-dating with every DoB before 2000 is a good choice in my experience. Because it includes a leap year and a nice round number. Each DoB and FromDate and ToDate will work in 2000 ...
WHERE DoB2000 >= FromDate AND DoB2000 <= ToDate
(This assumes that you are also indexing the new field to speed up the search, otherwise you will still get a scan, although it MAY be faster than the next alternative anyway.)
Alternatively, you can continue to use the EXTRACT template. But this will have a sad consequence; it is very dirty and you will never get an Index Seek, you will always get an index scanner. This is because the desired field is wrapped in a function call.
WHERE ( EXTRACT(month FROM e.DateOfBirth) > EXTRACT(month FROM FromDate) OR ( EXTRACT(month FROM e.DateOfBirth) = EXTRACT(month FROM FromDate) AND EXTRACT(day FROM e.DateOfBirth) >= EXTRACT(day FROM FromDate) ) ) AND ( EXTRACT(month FROM e.DateOfBirth) < EXTRACT(month FROM ToDate) OR ( EXTRACT(month FROM e.DateOfBirth) = EXTRACT(month FROM ToDate) AND EXTRACT(day FROM e.DateOfBirth) <= EXTRACT(day FROM ToDate) ) )
source share