March 28, 2024, 05:59:39 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Selecting Records by SQL Query

Started by Brian, June 18, 2009, 03:38:57 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Hi,

I have a database of names and addresses with dates of birth

I need to select records where age is not over 12 when the
record is selected. So, given a start date and an end date,
any selected record's age would not be over 12 by the
end date

Any SQL ideas?

Thanks a lot,

Brian

friet

Hi Brian,

I assume it does depend on the version of SQL you're using, but in MS SQL you can do :

"SELECT * from <tablename> where (year(curdate())-year(date-of-birth))<=12"

while not completely exact, this should give you a clue how to continue (because this doesn't take into account the month/day)
You would probably need to write a stored function to have a correct calculation  (and leave it out of your emergence code, so it gets executed on the server, probably much faster)

hope this helps..

regards,

Frank


Brian

Frank,

Thanks for your reply - this gives me a great starting point. I'll give it a go
tonight

Brian

Allan

Brian

Here is some code I have used with the Easy Database (MS ACCESS)

You just need to put your dates in as needed.

Hope it is of some help.

Allan