Subject Re: [firebird-support] select birthdays form the next several days
Author Alexandre Benson Smith
Christian Brümmer 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
>
>
>
>
Christian,

What about the following statement...

select
Name, BirthDate
from
Table
where
Cast('2000-' || extract(month from BirthDate) || '-' || extract(day
from BirthDate) as Date) between
Cast('2000-' || extract(month from Current_TimeStamp) || '-' ||
extract(day from Current_TimeStamp) as Date) and
Cast('2000-' || extract(month from Current_TimeStamp) || '-' ||
extract(day from Current_TimeStamp) as Date) + 14
order by
extract(month from BirthDate), extract(day from BirthDate)

No index will be used in a such query

see you !

--

Alexandre Benson Smith
Development
THOR Software e Comercial Ltda.
Santo Andre - Sao Paulo - Brazil
www.thorsoftware.com.br



--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.5/110 - Release Date: 22/09/2005