473,503 Members | 1,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BETWEEN and AND statements

I have a query with this Between statement as the criteria:
"Between [Enter 1st Qtr - (eg March 2003)] And [End Qtr - (eg June 2004)]"
If I key in June 2002 as the first quarter date and June 2004 as the second
quarter date I get data for June 2002 upto March 2004 not June 2004. How can
I change the Between statement to include June 2004 if I enter June 2004?
TIA
Tony Williams
Nov 13 '05 #1
6 4259
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cn**********@sparta.btinternet.com...
I have a query with this Between statement as the criteria:
"Between [Enter 1st Qtr - (eg March 2003)] And [End Qtr - (eg June 2004)]"
If I key in June 2002 as the first quarter date and June 2004 as the second
quarter date I get data for June 2002 upto March 2004 not June 2004. How can
I change the Between statement to include June 2004 if I enter June 2004?


What kind of field is this criteria being applied to? The entry "March 2003" is
meaningless when applied to a Date field. If applied to a calculated field that
produces "mmmm yyyy" output from a Date field the resulting filter would be an
alphabetical one, not chronological.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2
Sorry Rick I'm a little confused. I have the control as a date field with
the format mmmm yyyy and it seems to work as far other criteria are
concerned eg the following:
Between DateSerial(Year([Enter 1st Qtr End Date]),1,1) And [Enter 1st Qtr
End Date] Or Between DateSerial(Year([Enter 2nd Qtr End Date]),1,1) And
[Enter 2nd Qtr End Date]

Is that purely coincidence or am I missing something?
Thanks
Tony
PS Bit of an amateur so forgive the naivety!

"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:30*************@uni-berlin.de...
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cn**********@sparta.btinternet.com...
I have a query with this Between statement as the criteria:
"Between [Enter 1st Qtr - (eg March 2003)] And [End Qtr - (eg June 2004)]" If I key in June 2002 as the first quarter date and June 2004 as the second quarter date I get data for June 2002 upto March 2004 not June 2004. How can I change the Between statement to include June 2004 if I enter June
2004?
What kind of field is this criteria being applied to? The entry "March 2003" is meaningless when applied to a Date field. If applied to a calculated field that produces "mmmm yyyy" output from a Date field the resulting filter would be an alphabetical one, not chronological.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #3
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cn**********@titan.btinternet.com...
Sorry Rick I'm a little confused. I have the control as a date field with
the format mmmm yyyy and it seems to work as far other criteria are
concerned eg the following:
Between DateSerial(Year([Enter 1st Qtr End Date]),1,1) And [Enter 1st Qtr
End Date] Or Between DateSerial(Year([Enter 2nd Qtr End Date]),1,1) And
[Enter 2nd Qtr End Date]

Is that purely coincidence or am I missing something?
Thanks


Well this new code example you gave is using DateSerial() to produce an actual
Date value from the parameter being entered.

Someone entering "March 2003" into a parameter provided by your first code...

"Between [Enter 1st Qtr - (eg March 2003)] And [End Qtr - (eg June2004)]"

....that doesn't have DateSerial around it is just going to be treated as the
text string "March 2003".
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #4
So should I change the parameter to use DateSerial()?So it would become
Between DateSerial(Year([Enter 1st Qtr - (eg March 2003)] ,1,1) And
DateSerial(Year[End Qtr - (eg June2004)] ,1,1)
Sorry to be so slow on the uptake here, I would really like to understand
the difference
Thanks
Tony
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:30*************@uni-berlin.de...
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cn**********@titan.btinternet.com...
Sorry Rick I'm a little confused. I have the control as a date field with the format mmmm yyyy and it seems to work as far other criteria are
concerned eg the following:
Between DateSerial(Year([Enter 1st Qtr End Date]),1,1) And [Enter 1st Qtr End Date] Or Between DateSerial(Year([Enter 2nd Qtr End Date]),1,1) And
[Enter 2nd Qtr End Date]

Is that purely coincidence or am I missing something?
Thanks
Well this new code example you gave is using DateSerial() to produce an

actual Date value from the parameter being entered.

Someone entering "March 2003" into a parameter provided by your first code...
"Between [Enter 1st Qtr - (eg March 2003)] And [End Qtr - (eg June2004)]"

...that doesn't have DateSerial around it is just going to be treated as the text string "March 2003".
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #5
Ive tried this
Between DateSerial(Year([Enter 1st Qtr - eg March 2003]),1,1) And [End Qtr -
eg June2004]
and still get the same problem the query doesn't return data for June 2004
Tony
"Rick Brandt" <ri*********@hotmail.com> wrote in message
news:30*************@uni-berlin.de...
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cn**********@titan.btinternet.com...
Sorry Rick I'm a little confused. I have the control as a date field with the format mmmm yyyy and it seems to work as far other criteria are
concerned eg the following:
Between DateSerial(Year([Enter 1st Qtr End Date]),1,1) And [Enter 1st Qtr End Date] Or Between DateSerial(Year([Enter 2nd Qtr End Date]),1,1) And
[Enter 2nd Qtr End Date]

Is that purely coincidence or am I missing something?
Thanks
Well this new code example you gave is using DateSerial() to produce an

actual Date value from the parameter being entered.

Someone entering "March 2003" into a parameter provided by your first code...
"Between [Enter 1st Qtr - (eg March 2003)] And [End Qtr - (eg June2004)]"

...that doesn't have DateSerial around it is just going to be treated as the text string "March 2003".
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Nov 13 '05 #6
"Tony Williams" <tw@tcpinvalid.com> wrote in message
news:cn**********@hercules.btinternet.com...
So should I change the parameter to use DateSerial()?So it would become
Between DateSerial(Year([Enter 1st Qtr - (eg March 2003)] ,1,1) And
DateSerial(Year[End Qtr - (eg June2004)] ,1,1)
Sorry to be so slow on the uptake here, I would really like to understand
the difference


Your table has Date fields and will only understand comparisons to other date
values. The query...

SELECT * FROM SomeTable
WHERE DateField BETWEEN "March 2004" AND "June 2004"

.... will not work because "March 2004" is NOT a date it is a String. A person
can see that it represents a month and year but Access cannot.

You need a Query that will evaluate to...

SELECT * FROM SomeTable
WHERE DateField BETWEEN #03/01/2004# AND #06/30/2004#

Then you are comparing Dates to Dates. If you want your user to only have to
provide the month and year then your expression has to take those entries and
STILL end up with something that Access will know is a Date.

I prefer DateSerial, but you would have to feed it three separate arguments The
year and month would have to be provided with separate parameters and they would
all have to be numbers (you couldn't use "March" for example. CDate() can take
a string and convert it to a date and if it's not provided it will assume 1 for
the day.

SELECT * FROM SomeTable
WHERE DateValue
BETWEEN CDate([Enter 1st Qtr - (eg March 2003)])
AND CDate([End Qtr - (eg June 2003)])

However; the above will evaluate to...

SELECT * FROM SomeTable
WHERE DateField BETWEEN #03/01/2004# AND #06/01/2004#

Since June 1st is what is evaluated you will not actually get any records for
June unless they occur on June 1st at midnight. So you have to add an extra
month to the ending value.

SELECT * FROM SomeTable
WHERE DateValue
BETWEEN CDate([Enter 1st Qtr - (eg March 2003)])
AND DateAdd("m", 1, CDate([End Qtr - (eg June 2003)]))

You would really be better off dropping the self prompting parameter query and
feeding the criteria from a form. Self-prompting parameter queries are only
appropriate in the simplest of cases and are almost never used in a production
quality application.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2413
by: lkrubner | last post by:
Suppose I make a call to MySql and zero rows come back. How do I tell the difference between zero rows and failure?
11
1303
by: ATSkyWalker | last post by:
What's the difference between these 2 statements? If you have a String s="12345" s = "54321" But s = "5432"
2
2232
by: uli2003wien | last post by:
Dear group, we are dealing with some very specific problems with ODBC, where a connection from SQL-Server to Mysql works with ODBC-driver 3.51.10.00 and does NOT work with ODBC-driver...
2
16290
by: amos_s12 | last post by:
Hello everybody Is there a possibility to make a delay between two sql statements, namely one sql statement is performed, then there is a delay of some seconds and then rhe next statement is...
27
3154
by: hokieghal99 | last post by:
What is the difference between these two statements? Are there any major differences? const char filename = "ips_c.txt"; char filename = "ips_c.txt"; Thanks!!!
3
8421
by: kai | last post by:
Hi, All What is the the difference between If and #If? I read some VB.NET books, sometimes I see #If, but cannot tell why. Please help. Thanks Kai
6
8406
by: nikhilbhavsar | last post by:
Hi Friends , I want to know the exact difference between collection ID and qualifier. I also want to know in detail : When we perform BIND operation on a stored procedure, what we are actually...
13
10677
by: Jim Armstrong | last post by:
Hi all - This problem has been driving me crazy, and I'm hoping the answer is something stupid I am neglecting to see.... The procedure posted below is part of an Access/SQL database I have...
4
9448
by: arnuld | last post by:
i am unable to understand the difference between a "C++ expression" and a "C++ statement". this is what i get from C++ Primer: expression The smallest unit of computation. An expression...
9
19030
by: Logan Lee | last post by:
Hi. What's the difference between while and do while?
0
7084
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6991
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7458
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3167
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3154
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
736
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.