PC Review


Reply
Thread Tools Rate Thread

Date Range Query. Criteria based in a table.

 
 
Angela
Guest
Posts: n/a
 
      26th Jun 2010
Hi,


I have a table in below format.

ReportName StartDate EndDate Criteria CriteriaDetail Selection
AAA 01/01/2010 29/01/2010 RANGE BETWEEN [STARTDATE] AND [ENDDATE] YES/
NO
BBB 01/01/2010 01/01/2010 SAMEDATE YES/NO
CCC 31/12/2009 31/12/2009 YESTERDAY YES/NO

As I have to adjust my resulting query according to date changes, each
time I have to edit the parameters, like in case of range, I have to
edit the between statement each time.

I was looking for a way to make changes to this table & get the
results accordingly in the query instead of editing the conditions in
a query everytime.

The selection column will decide which line I would like to use for
what report.
I can change report names & adjust them as desired. Basic requirements
of all reports are same.

Both tables have date column in common as we are drilling information
datewise.
 
Reply With Quote
 
 
 
 
Karl Hoaglund
Guest
Posts: n/a
 
      26th Jun 2010
Hi Angela. Do I understand that you are trying to pull sets of
records from your table based on different date ranges? If so, I
think you want to use a query with parameters. The SQL syntax would
look like this (though it could be in a query object):

Select *
from MyTable
Where StartDate between [paramDateRangeBegin] and [paramDateRangeEnd]


When you run the query you can input different begin and end dates to
pull up different sets of records. Is this what you need to do?


Karl Hoaglund, MCSD
Microsoft Access Programmer
http://www.nexuscgi.net
 
Reply With Quote
 
Angela
Guest
Posts: n/a
 
      27th Jun 2010
Hey Karl,

Yes I have done that already.
I was looking for giving the dates in a table & then running the query
according to that.

Thanks for the reply anyways.
 
Reply With Quote
 
Karl Hoaglund
Guest
Posts: n/a
 
      27th Jun 2010
Hi Angela. Ah, I think I'm starting to understand. You want to use
the StartDate and EndDate in the table you mentioned in your first
message to filter the records that show up in your query. You could
use a cross join for this. The syntax would be like the following, if
we assume that you want to pull records from a table called Orders
that have an EnteredDate within the date range of the selected record
in a table called ReportCriteria.

Select o.*
from Orders as o cross join ReportCriteria as c
where (c.Selected is True) and (o.EnteredDate between c.StartDate and
c.EndDate)


A warning: if more than one criteria record is selected you'll get
multiple sets of records--duplicates--so you would want to take care
that only one record is selected at time.

Hope this helps.

Karl


Karl Hoaglund, MCSD
Microsoft Access Programmer
http://www.nexuscgi.net




 
Reply With Quote
 
Angela
Guest
Posts: n/a
 
      27th Jun 2010
Hey Karl,

I have managed to do that.
The warning message can be avoided if I use the "reportname" for the
criteria that I choose : )

Thanks again for the sql input.. ; )
Much appreciated.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Criteria based on another table He_Haa Microsoft Access Queries 4 27th Aug 2008 07:28 PM
Bucketing data based on DATE Range criteria =?Utf-8?B?c3VtaXRr?= Microsoft Excel Misc 1 20th May 2006 12:16 AM
Query Date Range Criteria Doesn't Include Last Date in Range Karl Burrows Microsoft Access Queries 6 10th Jun 2005 07:24 AM
Sum data based on company and date range criteria =?Utf-8?B?Q29uZGl0aW9uYWwgc3VtIHdpdGggZGF0ZSByYW5n Microsoft Excel Worksheet Functions 3 14th Oct 2004 06:50 PM
Using date range in query criteria Kathi Microsoft Access Queries 4 30th Aug 2004 03:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:26 PM.