dbTalk Databases Forums  

Newbie: Date range query by quarter

comp.databases.ms-access comp.databases.ms-access


Discuss Newbie: Date range query by quarter in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Mark
 
Posts: n/a

Default Newbie: Date range query by quarter - 11-30-2004 , 09:13 PM






Hi,

I'm trying to do query that will return all rows within the last quarter of
any year.
I've tried: "Between #10/1/????# And #12/31/????#" and I get an error
message:
"The expression you entered has an invalid date value."

If I run "Between #10/1/1995# And #12/31/1995#", it works fine, but for 1995
only.
I need to be able to return the last quarter of all years.

Any suggestions?

Thanks,
Mark.



Reply With Quote
  #2  
Old   
Dave M
 
Posts: n/a

Default Re: Newbie: Date range query by quarter - 11-30-2004 , 10:08 PM






Try Format([MyDate],"q") and then set the criterion 4

"Mark" <m.misener (AT) sympatico (DOT) ca> wrote

Quote:
Hi,

I'm trying to do query that will return all rows within the last quarter
of
any year.
I've tried: "Between #10/1/????# And #12/31/????#" and I get an error
message:
"The expression you entered has an invalid date value."

If I run "Between #10/1/1995# And #12/31/1995#", it works fine, but for
1995
only.
I need to be able to return the last quarter of all years.

Any suggestions?

Thanks,
Mark.





Reply With Quote
  #3  
Old   
MGFoster
 
Posts: n/a

Default Re: Newbie: Date range query by quarter - 11-30-2004 , 10:14 PM



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You could use the DatePart() function to get the quarter. E.g.:

SELECT ...
FROM ...
WHERE DatePart("q",Date_column) = 4

See the Access VBA help article "DatePart Function" for more info.

You could also use query parameters to have the user enter the quarter
they want. E.g.:

PARAMETERS [What quarter?] Byte;
SELECT ...
FROM ...
WHERE DatePart("Q", Date_column) = [What quarter?]

See the Access Help article "About parameter queries that prompt for
criteria" for more info.

Putting the DatePart() function on the left side of the equation in a
query's WHERE clause can slow down the run. That's because the query
will have to scan the whole table & convert the date to a quarter value.
If you want to improve the query's speed you can create a new, indexed
column in the table that holds the date's quarter. Then use the
quarter_column in the WHERE clause:

....WHERE quarter_column = 4

That's really a design/performance decision.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQa1FNYechKqOuFEgEQLHpwCdFTreHqKDY/6+kTTds/gDtfvosOIAoPQf
jNJNjIbmwbhCKCDwsPRlQMYM
=a2el
-----END PGP SIGNATURE-----


Mark wrote:
Quote:
Hi,

I'm trying to do query that will return all rows within the last quarter of
any year.
I've tried: "Between #10/1/????# And #12/31/????#" and I get an error
message:
"The expression you entered has an invalid date value."

If I run "Between #10/1/1995# And #12/31/1995#", it works fine, but for 1995
only.
I need to be able to return the last quarter of all years.

Reply With Quote
  #4  
Old   
Mark
 
Posts: n/a

Default Re: Newbie: Date range query by quarter - 12-01-2004 , 05:32 PM




"Mark" <m.misener (AT) sympatico (DOT) ca> wrote

Quote:
Hi,

I'm trying to do query that will return all rows within the last quarter
of any year.
I've tried: "Between #10/1/????# And #12/31/????#" and I get an error
message:
"The expression you entered has an invalid date value."

If I run "Between #10/1/1995# And #12/31/1995#", it works fine, but for
1995 only.
I need to be able to return the last quarter of all years.

Any suggestions?

Thanks,
Mark.
Thanks for the advice everyone.
I've decided to make use of the DatePart("q",[OrderDate])=4 option.

Mark.




Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.