Subject Re: select birthdays form the next several days
Author Ali Gökçen
my lunch is ok, here is my personal solution:

select name,bdate from person

where

bdate between

cast( extract(day from current_date) -
(case when extract(day from current_date)=29 and extract(month
from current_date)=2 then 28 else 0) ||
'.'||extract(month from current_date) +
(case when extract(day from current_date)=29 and extract(month
from current_date)=2 then 1 else 0)||
'.'||extract(year from bdate) as date)

AND -- if current date is elapsed then interpret the base date as 1
march

cast( extract(day from current_date) -
(case when extract(day from current_date)=29 and extract(month
from current_date)=2 then 28 else 0) ||
'.'||extract(month from current_date) +
(case when extract(day from current_date)=29 and extract(month
from current_date)=2 then 1 else 0)||
'.'||extract(year from bdate) as date)
+ case when extract(day from current_date)=29 and extract
(month from current_date)=2 then 13 else 14)
-- tolerate the date shifting


Theorically it should be do index scan.
I preffer CPU calculations instead of DISK I/O.

-Ali

--- In firebird-support@yahoogroups.com, Christian Brümmer
<christian@b...> wrote:
> Hi Firebird group,
>
> I have a table with the name as varchar and the birthday as date.
>
> And now a simple question: how can a get with a simple SQL
statement the
> name of the people, who will have birthday within the next 14 (for
> example) days. Is it possible to do this in a single SQL statement?
>
> The question is easy, but the solution not, correct?
>
> I have two ideas:
>
> 1st idea: in my application, I will calculate the days and split
it into
> months and days. In the SQL statement, I will filter the
information
> with WHERE to check the months and days.
>
> 2nd idea: I make a second column: birthday_calc, which has a fixed
year
> (2000) instead of the original birth year. So I can get the data,
with a
> simple: where birthday_calc >= '2000-09-10' and birthday_calc <=
> '2000-09-24'
>
> I don't like them both, do you have another better idea?
>
> Thanks in advance
>
> Christian