473,394 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Queries using different date ranges

I have a query set up to gather together data between two specified dates.
Shown in the query column as:

Between #24/09/2004# And #01/10/2004#

Is it possible to enter several different date ranges, ie between 24/09/2004
and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?

If I enter the "Between" criteria on different lines it returns no data.

Some pointers would be useful - thanks.

I'm using Access 2000 on Win XP Home with SP2 installed.

Steve.
Nov 13 '05 #1
12 6318
Pull down your date field twice into the query grid. Put he following in the
criteria under the first one:
Between #24/09/2004# And #01/10/2004#
and put he following in the criteria under the second one:
Between #05/10/2004# And #07/10/2004#

Note: both criteria expressions must be in the same row

When you have criteria set for more than one field in the same row, Access
treats them as AND conditions.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@news6.svr.pol.co.uk...
I have a query set up to gather together data between two specified dates.
Shown in the query column as:

Between #24/09/2004# And #01/10/2004#

Is it possible to enter several different date ranges, ie between 24/09/2004 and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?

If I enter the "Between" criteria on different lines it returns no data.

Some pointers would be useful - thanks.

I'm using Access 2000 on Win XP Home with SP2 installed.

Steve.

Nov 13 '05 #2
Hi, thanks for your suggestion, although I still can't get it to work. My
two DATE columns are shown thus:

Field: Date
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: Between #24/09/2004# And #01/10/2004#
Or:

Same in the next column of the query grid, with the other "between" dates.

Access 2000 returns no data. I have 9 columns within the query grid.

I can't understand why Access wouldn't just return a grand total for these
two sets of dates.

Thanks,

Steve.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:Oj***************@newsread2.news.atl.earthlin k.net...
Pull down your date field twice into the query grid. Put he following in
the
criteria under the first one:
Between #24/09/2004# And #01/10/2004#
and put he following in the criteria under the second one:
Between #05/10/2004# And #07/10/2004#

Note: both criteria expressions must be in the same row

When you have criteria set for more than one field in the same row, Access
treats them as AND conditions.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@news6.svr.pol.co.uk...
I have a query set up to gather together data between two specified
dates.
Shown in the query column as:

Between #24/09/2004# And #01/10/2004#

Is it possible to enter several different date ranges, ie between

24/09/2004
and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?

If I enter the "Between" criteria on different lines it returns no data.

Some pointers would be useful - thanks.

I'm using Access 2000 on Win XP Home with SP2 installed.

Steve.


Nov 13 '05 #3
Steve,

(from one Steve to another!)

Change your query to a Select query. Be sure to include all the fields you
want in your crosstab as well as the date field twice. Consider this query
as the "data" query. Once you have this query returning the records you
want, create a new crosstab query based on the first query. Only include the
fields you want to report. The criteria will be in the first query so you
don't need any criteria in the crosstab.

Before you do the above however, change the name of the field you named
"Date". Date is a reserved word in Access and you should not use it for the
name of anything.

Steve
PC Datasheet
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@newsg2.svr.pol.co.uk...
Hi, thanks for your suggestion, although I still can't get it to work. My
two DATE columns are shown thus:

Field: Date
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: Between #24/09/2004# And #01/10/2004#
Or:

Same in the next column of the query grid, with the other "between" dates.

Access 2000 returns no data. I have 9 columns within the query grid.

I can't understand why Access wouldn't just return a grand total for these
two sets of dates.

Thanks,

Steve.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:Oj***************@newsread2.news.atl.earthlin k.net...
Pull down your date field twice into the query grid. Put he following in
the
criteria under the first one:
Between #24/09/2004# And #01/10/2004#
and put he following in the criteria under the second one:
Between #05/10/2004# And #07/10/2004#

Note: both criteria expressions must be in the same row

When you have criteria set for more than one field in the same row, Access treats them as AND conditions.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@news6.svr.pol.co.uk...
I have a query set up to gather together data between two specified
dates.
Shown in the query column as:

Between #24/09/2004# And #01/10/2004#

Is it possible to enter several different date ranges, ie between

24/09/2004
and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?

If I enter the "Between" criteria on different lines it returns no data.
Some pointers would be useful - thanks.

I'm using Access 2000 on Win XP Home with SP2 installed.

Steve.



Nov 13 '05 #4
Thanks Steve,

This didn't work either. Have changed the query type to a Select Query, but
still no data is returned when the query is run - only the column headings
appear. Could this be caused by other "and" criteria set up as well as the
dates? I'm somewhat confused.

I can send a screen shot if that helps - these things are always difficult
to explain clearly.

many thanks for your help so far.

Steve.

"PC Datasheet" <no****@nospam.spam> wrote in message
news:m9***************@newsread3.news.atl.earthlin k.net...
Steve,

(from one Steve to another!)

Change your query to a Select query. Be sure to include all the fields you
want in your crosstab as well as the date field twice. Consider this query
as the "data" query. Once you have this query returning the records you
want, create a new crosstab query based on the first query. Only include
the
fields you want to report. The criteria will be in the first query so you
don't need any criteria in the crosstab.

Before you do the above however, change the name of the field you named
"Date". Date is a reserved word in Access and you should not use it for
the
name of anything.

Steve
PC Datasheet
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@newsg2.svr.pol.co.uk...
Hi, thanks for your suggestion, although I still can't get it to work.
My
two DATE columns are shown thus:

Field: Date
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: Between #24/09/2004# And #01/10/2004#
Or:

Same in the next column of the query grid, with the other "between"
dates.

Access 2000 returns no data. I have 9 columns within the query grid.

I can't understand why Access wouldn't just return a grand total for
these
two sets of dates.

Thanks,

Steve.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:Oj***************@newsread2.news.atl.earthlin k.net...
> Pull down your date field twice into the query grid. Put he following
> in
> the
> criteria under the first one:
> Between #24/09/2004# And #01/10/2004#
> and put he following in the criteria under the second one:
> Between #05/10/2004# And #07/10/2004#
>
> Note: both criteria expressions must be in the same row
>
> When you have criteria set for more than one field in the same row, Access > treats them as AND conditions.
>
> --
> PC Datasheet
> Your Resource For Help With Access, Excel And Word Applications
> re******@pcdatasheet.com
> www.pcdatasheet.com
>
>
> "Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
> news:cl**********@news6.svr.pol.co.uk...
>> I have a query set up to gather together data between two specified
>> dates.
>> Shown in the query column as:
>>
>> Between #24/09/2004# And #01/10/2004#
>>
>> Is it possible to enter several different date ranges, ie between
> 24/09/2004
>> and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?
>>
>> If I enter the "Between" criteria on different lines it returns no data. >>
>> Some pointers would be useful - thanks.
>>
>> I'm using Access 2000 on Win XP Home with SP2 installed.
>>
>> Steve.
>>
>>
>
>



Nov 13 '05 #5
Go to the database window, queries tab. Right click on your query and make a
copy for testing. In the copy, starting left to right, delete one criteria
and run the query. Repeat until you get records returned. Examine the last
criteria you deleted to determine why that criteria does not return any
records.

Steve
PC Datasheet
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@news8.svr.pol.co.uk...
Thanks Steve,

This didn't work either. Have changed the query type to a Select Query, but still no data is returned when the query is run - only the column headings
appear. Could this be caused by other "and" criteria set up as well as the dates? I'm somewhat confused.

I can send a screen shot if that helps - these things are always difficult
to explain clearly.

many thanks for your help so far.

Steve.

"PC Datasheet" <no****@nospam.spam> wrote in message
news:m9***************@newsread3.news.atl.earthlin k.net...
Steve,

(from one Steve to another!)

Change your query to a Select query. Be sure to include all the fields you want in your crosstab as well as the date field twice. Consider this query as the "data" query. Once you have this query returning the records you
want, create a new crosstab query based on the first query. Only include
the
fields you want to report. The criteria will be in the first query so you don't need any criteria in the crosstab.

Before you do the above however, change the name of the field you named
"Date". Date is a reserved word in Access and you should not use it for
the
name of anything.

Steve
PC Datasheet
"Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
news:cl**********@newsg2.svr.pol.co.uk...
Hi, thanks for your suggestion, although I still can't get it to work.
My
two DATE columns are shown thus:

Field: Date
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: Between #24/09/2004# And #01/10/2004#
Or:

Same in the next column of the query grid, with the other "between"
dates.

Access 2000 returns no data. I have 9 columns within the query grid.

I can't understand why Access wouldn't just return a grand total for
these
two sets of dates.

Thanks,

Steve.
"PC Datasheet" <no****@nospam.spam> wrote in message
news:Oj***************@newsread2.news.atl.earthlin k.net...
> Pull down your date field twice into the query grid. Put he following
> in
> the
> criteria under the first one:
> Between #24/09/2004# And #01/10/2004#
> and put he following in the criteria under the second one:
> Between #05/10/2004# And #07/10/2004#
>
> Note: both criteria expressions must be in the same row
>
> When you have criteria set for more than one field in the same row,

Access
> treats them as AND conditions.
>
> --
> PC Datasheet
> Your Resource For Help With Access, Excel And Word Applications
> re******@pcdatasheet.com
> www.pcdatasheet.com
>
>
> "Steve Elliott" <st***@olympicradio.freeserve.co.uk> wrote in message
> news:cl**********@news6.svr.pol.co.uk...
>> I have a query set up to gather together data between two specified
>> dates.
>> Shown in the query column as:
>>
>> Between #24/09/2004# And #01/10/2004#
>>
>> Is it possible to enter several different date ranges, ie between
> 24/09/2004
>> and 01/10/2004 together with 05/10/2004 and 07/10/2004 ?
>>
>> If I enter the "Between" criteria on different lines it returns no

data.
>>
>> Some pointers would be useful - thanks.
>>
>> I'm using Access 2000 on Win XP Home with SP2 installed.
>>
>> Steve.
>>
>>
>
>



Nov 13 '05 #6
If I do the date in that format, Access simply changes it to UK date format.
Individual dates and between dates work fine for one set of criteria. It's
when two or more criteria date ranges or individual dates are entered it
returns no result.

#29/09/2004#?!??

When using #'s, dates must be in the American format of MM/DD/YYYY.

Nov 13 '05 #7
Go to the database window, queries tab. Right click on your query and make
a
copy for testing. In the copy, starting left to right, delete one criteria
and run the query. Repeat until you get records returned. Examine the last
criteria you deleted to determine why that criteria does not return any
records.


Tried this, and still it doesn't work. I have also set up a completely new
query based on different data, and created several date fields, with each
date required in each - this still returns a blank result. I can't see how
Access calculates totals between two sets of dates, but can't work with
individual dates that are not consecutive.

Thanks for all your suggestions though - I'm battling on... there must be a
way.

Steve.
Nov 13 '05 #8
Steve Elliott wrote:
If I do the date in that format, Access simply changes it to UK date format.
Individual dates and between dates work fine for one set of criteria. It's
when two or more criteria date ranges or individual dates are entered it
returns no result.

#29/09/2004#?!??

When using #'s, dates must be in the American format of MM/DD/YYYY.


Have you done a View/SQL from the menu?

If you don't see something like
DateField Between Date1 And Date2 Or _
DateField Between Date3 and Date4
then you are not following the initial instructions...to put each of
your date ranges on separate criteria rows to generate an OR condition,
not an AND.

And if you still can't get it, modify it manually from the SQL view window.

Nov 13 '05 #9
Success ! If I show dates on SAME line with an OR between each individual
date, Access sums the totals from each of these dates and produces a result.

Logically I would have thought the AND command would do that, but apparently
not.

Thanks for your help.

Steve.
Have you done a View/SQL from the menu?

If you don't see something like
DateField Between Date1 And Date2 Or _
DateField Between Date3 and Date4
then you are not following the initial instructions...to put each of your
date ranges on separate criteria rows to generate an OR condition, not an
AND.

And if you still can't get it, modify it manually from the SQL view
window.

Nov 13 '05 #10
"PC Datasheet" wrote:
Pull down your date field twice into the query grid. Put he following in the
criteria under the first one:
Between #24/09/2004# And #01/10/2004#
and put he following in the criteria under the second one:
Between #05/10/2004# And #07/10/2004#

Note: both criteria expressions must be in the same row

When you have criteria set for more than one field in the same row, Access
treats them as AND conditions.


The problem with this is that any given date cannot be between both
ranges at the same time. No records could ever be returned in that
case.
Nov 13 '05 #11
"Steve Elliott" wrote:
Logically I would have thought the AND command would do that, but apparently
not.
Think about it this way: By using 'AND', you are saying that the date
must be between both ranges. Any date between 24/9/2004 and 01/10/2004
cannot possible also be between 05/10/2004 and 07/10/2004.

By using 'OR', you are saying, "Give me all records where the date is
either between this range OR that range."

Another analogy would be, "Show me all pets that are both a Cat AND a
Dog" versus "Show me all pets that are either a Cat OR a Dog". If you
asked for the first, it is not likely the pet store would have any
animals that is both a Cat AND a Dog. But if you asked for the second,
you would be shown all cats and dogs in the store.

Make sense?
Success ! If I show dates on SAME line with an OR between each individual
date, Access sums the totals from each of these dates and produces a result.


You would get the same results if you put each Between clause on
separate rows, as in:

Field: Date
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: Between #24/09/2004# And #01/10/2004#
Or: Between #05/10/2004# And #07/10/2004#

However, if you have criterea in addition to this date range, you
would have to copy that criterea to the second line also.

For example, if your date field must fall between either of those two
ranges and the State must also be 'CA', the column for the state field
would look like:

Field: State
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: 'CA'
Or: 'CA'

Having the 'CA' listed on both lines makes the 'CA' criterea
applicable to both date ranges. In this case, the query would ask the
following 2 questions about each record (1 question per line of
criterea):

1) Does State='CA' and is Date between 24/09/2004 and 01/10/2004?
2) Does State='CA' and is Date between 05/10/2004 and 07/10/2004?

If it answers 'Yes' to either question, then the record is included in
the results. If not, the record is excluded.
However, if you have the 'CA' criterea only on the first line, then
you would be asking for all records where the state is 'CA' and the
date is between the first range, OR records where the date is between
the second range (regardless of the State value). In this case, the
query would ask the following 2 questions about each record:

1) Does State='CA' and is Date between 24/09/2004 and 01/10/2004?
2) Is Date between 05/10/2004 and 07/10/2004?

If it answers 'Yes' to either question, then the record is included in
the results. If not, the record is excluded.

See the difference?
-Dennis Borg
Nov 13 '05 #12
You're right, that does sound logical - I'm having a bad "Access" week :(

Works fine for several dates, ie: 04/10/2004 or 10/10/2004 or 12/10/1004 in
same query - in fact it works for a very long string of various dates.

Thanks for the advice/suggestions/explanation.

Steve.
"DenBorg" <de******@yahoo.com> wrote in message
news:dc**************************@posting.google.c om...
"Steve Elliott" wrote:
Logically I would have thought the AND command would do that, but
apparently
not.


Think about it this way: By using 'AND', you are saying that the date
must be between both ranges. Any date between 24/9/2004 and 01/10/2004
cannot possible also be between 05/10/2004 and 07/10/2004.

By using 'OR', you are saying, "Give me all records where the date is
either between this range OR that range."

Another analogy would be, "Show me all pets that are both a Cat AND a
Dog" versus "Show me all pets that are either a Cat OR a Dog". If you
asked for the first, it is not likely the pet store would have any
animals that is both a Cat AND a Dog. But if you asked for the second,
you would be shown all cats and dogs in the store.

Make sense?
Success ! If I show dates on SAME line with an OR between each
individual
date, Access sums the totals from each of these dates and produces a
result.


You would get the same results if you put each Between clause on
separate rows, as in:

Field: Date
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: Between #24/09/2004# And #01/10/2004#
Or: Between #05/10/2004# And #07/10/2004#

However, if you have criterea in addition to this date range, you
would have to copy that criterea to the second line also.

For example, if your date field must fall between either of those two
ranges and the State must also be 'CA', the column for the state field
would look like:

Field: State
Table: Transactions
Total: Where
Crosstab:
Sort:
Criteria: 'CA'
Or: 'CA'

Having the 'CA' listed on both lines makes the 'CA' criterea
applicable to both date ranges. In this case, the query would ask the
following 2 questions about each record (1 question per line of
criterea):

1) Does State='CA' and is Date between 24/09/2004 and 01/10/2004?
2) Does State='CA' and is Date between 05/10/2004 and 07/10/2004?

If it answers 'Yes' to either question, then the record is included in
the results. If not, the record is excluded.
However, if you have the 'CA' criterea only on the first line, then
you would be asking for all records where the state is 'CA' and the
date is between the first range, OR records where the date is between
the second range (regardless of the State value). In this case, the
query would ask the following 2 questions about each record:

1) Does State='CA' and is Date between 24/09/2004 and 01/10/2004?
2) Is Date between 05/10/2004 and 07/10/2004?

If it answers 'Yes' to either question, then the record is included in
the results. If not, the record is excluded.

See the difference?
-Dennis Borg

Nov 13 '05 #13

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

Similar topics

2
by: bobb | last post by:
Is there a way to select count(*) by grouping by date, and having multiple date ranges? combining... select field,count(*) from table where datefield > 2004/1/1 and datefield < 2004/1/31 and...
3
by: Metal Dave | last post by:
Hi all, Currently our product has a setup that stores information about transactions in a transaction table. Additionally, certain transactions pertain to specific people, and extra information...
4
by: kinne | last post by:
The following code is supposed to reverse the date in "yyyy-mm-dd" format, but it produces different results in Firefox 1.0 and in Internet Explorer 6SP1. In Firefox, the result is correct...
2
by: Adam | last post by:
Hi All, This may be a really obvious thing that I'm missing ... but if anyone can help, I'd appreciate it. I have MS Access 2000: I'm using it for a CRM type database. I have a table with...
7
by: Jim Crate | last post by:
I have a couple queries in a PL/PGSQL function which execute very slowly (around one minute each) which execute in .5 second when not executed from within the function. Is there any way to...
67
by: PC Datasheet | last post by:
Transaction data is given with date ranges: Beginning End 4/1/06 4/4/06 4/7/06 4/11/06 4/14/06 4/17/06 4/18/06 4/21/06 426/06 ...
0
by: Christoph Haas | last post by:
Hi, list... I have written an application in Perl some time ago (I was young and needed the money) that parses multiple large text files containing nested data structures and allows the user to...
3
by: wsox66 | last post by:
I am new to Access and need some help building a report. I have looked through previous posts on reports but none of them seem to answer my question completely. I am using Access 2003 and I have...
1
by: JosAH | last post by:
Greetings, Introduction This week we start building Query objects. A query can retrieve portions of text from a Library. I don't want users to build queries by themselves, because users make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.