If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Query on Month Only of Date Field

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Feb 2009
Posts: 28
Query on Month Only of Date Field

How do I phrase a query to pull data from a table based upon only the month? I tried
Like "*" & [Enter Month] & "*" but that pulls the wrong months as well as the ones I want.

I.E. If I want month 1 it'll pull 1 and 10, 11 and 12.
Reply With Quote
  #2 (permalink)  
Old
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 12,176
in short the db is not pulling the wrong months, its doing precisely what you have requested, based on your table/column design

how are you letting your users define month?
are you using number (3), abbreviation ("Mar") or full name ("March")
are you storing the date as sting (yuck) or as a date time value?

I'd suggest you restrict your users inputs by using a form which validates anythign sent to the SQL engine is legit, that means you can then comntrol what the users does, but it alos means that there is a consistent interface (it means for example that a user can rerun a report or a series of reports using the same date/month)

so
if you are storing a date as string (and your really really shouldn't) you can use the like construct
however it depends on how your dates are stored say they are stored in UK / Aus and other 'sensible countries where the month is the middle part of the date you could look for "*/01/*" to find January or "*/1/*"
conceivably you may have to do both, you may also have to look for "*Jan/*" AND "*January*"
if you use US dates
look for "* 1/" and "* 01/* and so on......
you will get yourself tied in knots if you persist in storing dates as sting values.

its far easier if they were stored as date time values

you'd just use where month(mydatecolumn)= mynumericvalue

instead of
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Feb 2009
Posts: 28
The field in the table is a date/time format with the default being date() and the format of m

How can I get it to just search on the month?
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Feb 2009
Posts: 28
Got it!
I put a column in my query like this:
MonthValue: Month([DateField])
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On