# Query by Intervals within Date Range

Table:
Start Date, Stop Date
If a Stop Date is Null, the record is active still.

User Selects:
1. Report Period (week, quarter), for this example week.
2. The Interval (month, quarter, year), for this example month
3. The Range of Start Dates (ie. 1/1/00 to 6/1/00)

Output (could be by row or column):
Period:        1/29/00|2/5/00|2/12/00|2/19/00|2/26/00|...6/8/00
Percent Active:PA     |PA    |PA     |PA     |PA     |...PA

Where PA = the % of active records at the Interval.The PA % = (Count(Active Records)/Count(Active + Inactive Records)) FOR Starts withing the specified Week!

In this example:
Starts from 1/29/00 to 2/4/00 would be measured to find the PA at the 1 month mark. 2/5 to 2/11, 2/12 to 2/19 etc.

Active record is one where the stop date IS NULL or the (stop date - start date)>Interval (In this case one month).
An Inactive Record = (stop date - start date)<Interval
###### Who is Participating?

Commented:
Small remark PsychoDazey, the " > AND < " is seen by access as TWO compares. Using BETWEEN as only ONE !

This insert is not "matching" my 2) comment as it should insert additionally the period (week/month/quarter) and a NZ should be used for the NULL enddate !

Nic;o)
0

Commented:
I dont understand you're question.  Are you asking how to write the entire query you need or just how to tell it to look between the dates?
0

Commented:
Nice piece of work to do douglaskarr!

I solved a similar problem with:
1) A module that "generates" the measuring points (week, month,quarter) and writes them to a (temp) table.
2) A module that returns all "hits" on one measuring point. (For weeks every "hit" translates in a table row with the hit-weeknumber) Here the enddate is used as NZ(enddate,#2999-12-31#) to make sure they hit.
3) A crosstable query that links the generated periods (as "master") to the created rows from 2). (The module is executed for all periods, but there can be periods without hits!)

Lost track or do you see the logic of this approach ?

Nic;o)
0

Author Commented:
PsychoDazey:  I believe it's a series of queries to get the result.  The most difficult thing for me to figure out is generating the date ranges (start date + interval...) to populate the table.

Nico:  I understand the logic - let me do some work and generate some follow up questions.
0

Commented:
"INSERT INTO table1 SELECT * FROM table2 WHERE datefield > #" & me![startdate] & "# AND < #" & me![stopdate] & "#"
you could also use the between keyword.
you have to remember to enclose the dates in #'s
0

Commented:
Hence my comment on using the between.
As Douglas stated, it will probably be a series of questions to walk him all the way through this, by this statement I am sensing he is fairly new to vba.  My next step would have been to introduce the IsNull() function (my personal preference over the Nz)
0

Author Commented:
Wow.  I let this one go for a while.  Please let me review and get some testing underway.
0

Technical consultant & graphic designCommented:
Please update the expert here who have so willingly stepped in to help you, since much time has passed since your last comments, and Email notifications may not have been generated to the participating experts here due to some problems at that time.  If you've been helped, accept the respective question by that expert to grade and close it.

Somewhat off-topic, but important.

WindowsUpdate - Critical Update alert March 28, 2002 from Microsoft
http://www.microsoft.com/technet/treeview/default.asp?url=/technet/security/bulletin/ms02-015.asp
Synopsis:
Microsoft Security Bulletin MS02-015
28 March 2002 Cumulative Patch for Internet Explorer
Originally posted: March 28, 2002
Summary
Who should read this bulletin: Customers using Microsoft® Internet Explorer
Impact of vulnerability: Two vulnerabilities, the most serious of which would allow script to run in the Local Computer Zone.
Maximum Severity Rating: Critical
Recommendation: Consumers using the affected version of IE should install the patch immediately.
Affected Software:
Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5
Microsoft Internet Explorer 6.0

Thought you'd appreciate knowing this.
":0)
Asta
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.