Link to home
Start Free TrialLog in
Avatar of douglaskarr
douglaskarr

asked on

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
Avatar of PsychoDazey
PsychoDazey

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?
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)
Avatar of douglaskarr

ASKER

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.
"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
ASKER CERTIFIED SOLUTION
Avatar of nico5038
nico5038
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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)
Wow.  I let this one go for a while.  Please let me review and get some testing underway.  
Avatar of Asta Cu
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.

****************************** ALERT********************************
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