🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #528

Re: Birthdate Query

#528
From: Brent Rose
Date: Fri, 16 Nov 2007 05:42
31 lines
2226 bytes
I have used a Month-Day integer field like this for birthdays (mdd) and 
indexed it (only 366 unique values) with reasonable success on a table of a 
few tens-of-thousands of records. It was the only workable solution I ever 
came up with.

Having the low-selectivity index was better than not having it. Cannot say I 
ever tested or compared a string field equivalent.

NB If you want to query eg "whose birthday is it this week", then things get 
a little trickier when you span 2 calendar years.

I ended up creating a stored procedure accepting a from and to date, doing 
the necessary date manipulations, then using a generic where clause like:

  where
   (BirthMonthDay between :FromMonthDay and :ToMonthDay) or
   (BirthMonthDay >= :AfterMonthDay)

If you spanned 2 years, then the AfterMonthDay clause is required to pick up 
the birthdays on the tail end of the earlier year. If you did not span 2 
years, then AfterMonthDay could be set to 9999 and catch nothing.

I found it more efficient to do this in my case - but you may find it easier 
to compile the SQL in the application instead and only have the 
"AfterMonthDay" clause when actually required...


-- 
Brent Rose
Whats On Report
brent@whatson.co.nz 
Technical Details
Message-ID: <473d2d91$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4726a766@newsgroups.borland.com> <4726b05b$1@newsgroups.borland.com> <4726efdc$1@newsgroups.borland.com> <472777c9$1@newsgroups.borland.com> <4727994a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,d9969aee39c0cba7
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Brent Rose" <brent@whatson.co.nz>
Newsgroups: borland.public.interbase.sql
References: <4726a766@newsgroups.borland.com> <4726b05b$1@newsgroups.borland.com> <4726efdc$1@newsgroups.borland.com> <472777c9$1@newsgroups.borland.com> <4727994a$1@newsgroups.borland.com>
Subject: Re: Birthdate Query
Date: Fri, 16 Nov 2007 18:42:02 +1300
Lines: 33
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 203.79.66.167
Message-ID: <473d2d91$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1195191697 203.79.66.167 (15 Nov 2007 21:41:37 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail