How to get rows when only querying on the month of a birth date

B

Blackberry

Hi All

This is a good one that's baked my noodle!!

I have a standard table with lets say 2 cols:

NAME string
DOB date

Example rows may be:

NAME DOB
Gary Barlow 24-3-2002
John Barlow 24-11-2001
Bob Barlow 7-7-1999
Bill Barlow 6-3-1999
etc

I need to build a query that will get me all the rows back that were born in
say March (3), which means the above would bring back Gary and Bill even
though the birth day and year might be different - is this possible??!?!?

Thanks
 
B

Bob Quintal

Hi All

This is a good one that's baked my noodle!!

I have a standard table with lets say 2 cols:

NAME string
DOB date

Example rows may be:

NAME DOB
Gary Barlow 24-3-2002
John Barlow 24-11-2001
Bob Barlow 7-7-1999
Bill Barlow 6-3-1999
etc

I need to build a query that will get me all the rows back that
were born in say March (3), which means the above would bring back
Gary and Bill even though the birth day and year might be
different - is this possible??!?!?

Thanks
Sure, and easy too. Use the month() function to extract that part of
the date and set your criteria aginst this calculated field.

Paste this into the SQL view of the query builder and switch back to
design view to see how it looks. be sure to change [standard table]
to the real name of your table.

SELECT [name], year([DOB]) as Birthyear FROM [standard table] WHERE
Month([DOB]) = 3

I'd also change your name field to something more meaningful, such
as ClientName, because name is a reserved word in Access and Access
gets confused during some macros and code, between what you've
called name and the program designers called name.
 
B

Blackberry

Genius!!

Hi All

This is a good one that's baked my noodle!!

I have a standard table with lets say 2 cols:

NAME string
DOB date

Example rows may be:

NAME DOB
Gary Barlow 24-3-2002
John Barlow 24-11-2001
Bob Barlow 7-7-1999
Bill Barlow 6-3-1999
etc

I need to build a query that will get me all the rows back that
were born in say March (3), which means the above would bring back
Gary and Bill even though the birth day and year might be
different - is this possible??!?!?

Thanks
Sure, and easy too. Use the month() function to extract that part of
the date and set your criteria aginst this calculated field.

Paste this into the SQL view of the query builder and switch back to
design view to see how it looks. be sure to change [standard table]
to the real name of your table.

SELECT [name], year([DOB]) as Birthyear FROM [standard table] WHERE
Month([DOB]) = 3

I'd also change your name field to something more meaningful, such
as ClientName, because name is a reserved word in Access and Access
gets confused during some macros and code, between what you've
called name and the program designers called name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top