?
Solved

Access Query Grouping Dates

Posted on 2012-09-06
7
Medium Priority
?
468 Views
Last Modified: 2012-09-07
This isn't an easy task, but I was wondering if this is would be possible.

Below details is an example of a client service history. I need to somehow group the clients history into service periods.  It involves identifying break in consecutive days.

The reason why the client may exit and reenter on same day is because the entry and exit dates contain time stamps. Basically the person left the building to seek medical service and then returned.  

Details
Client       Provider Id      Entry Date      Exit Date
1460      Engagement      7/13/2011      7/14/2011
1460      Engagement      7/14/2011      7/21/2011
1460      Engagement      7/21/2011      7/26/2011
1460      Engagement      7/26/2011      8/3/2011
1460      Engagement      8/8/2011                8/9/2011
1460      Engagement      8/9/2011               8/12/2011
1460      Engagement      8/12/2011      8/19/2011
1460      Engagement      10/7/2011      10/8/2011
1460      Engagement      10/8/2011      10/10/2011
1460      Engagement      10/11/2011      10/12/2011
1460      Engagement      10/13/2011      10/17/2011
1460      Engagement      10/17/2011      10/19/2011
1460      Engagement      10/19/2011      10/20/2011
1460      Engagement      10/20/2011      10/21/2011
1460      Engagement      10/21/2011      10/21/2011
1460      Engagement      10/22/2011      10/23/2011
1460      Engagement      10/23/2011      10/24/2011
1460      Engagement      10/24/2011      10/26/2011
1460      Engagement      10/26/2011      10/27/2011
1460      Engagement      10/27/2011      10/28/2011
1460      Engagement      10/28/2011      10/31/2011
1460      Engagement      11/9/2011      11/10/2011
1460      Engagement      12/14/2011      12/15/2011
1460      Engagement      12/15/2011      12/16/2011

Results
Client       Provider Id      Entry Date      Exit Date
1460      Engagement      7/13/2011      8/03/2011
1460      Engagement      8/08/2011      8/19/2011
1460      Engagement      10/07/2011      10/31/2011
1460      Engagement      11/09/2011      11/10/2011
1460      Engagement      12/14/2011      12/16/2011
0
Comment
Question by:jbakestull
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38372953
That could be:

Select
  Client,
  [Provider Id],
  Min([Entry Date]) As EntryDate,
  Max([Exit Date]) As ExitDate
From
  tblYourTable
Group By
  Client,
  [Provider Id],
  Year([Entry Date]),
  Month([Entry Date]);

/gustav
0
 
LVL 77

Expert Comment

by:peter57r
ID: 38372977
You're not going to do this in a query.  It will require a VBA procedure.  Is that an acceptable approach?
0
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38373172
Are you attempting to do this for a specific (short) time period for a single client, or for several years for multiple clients?
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:jbakestull
ID: 38373189
Sorry, went out to lunch with wife. We don't get to do that very often.

Thanks for the responses, VBA is fine, for multiple clients over several years.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38375120
As I assume your test data is representative - where the break in consecutive days happens between months - the query will work for multiple clients over several years.

/gustav
0
 
LVL 77

Accepted Solution

by:
peter57r earned 2000 total points
ID: 38375611
Have a look at the attached example...

Data in tbl1
Run the procedure GetRanges
Results in tbl2
Database241.mdb
0
 

Author Comment

by:jbakestull
ID: 38377750
peter57r, I'm amazed. I will play with this over the weekend and get back with you. Thank you. You answered my question and did an awesome job. 500 points is really not enough.
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question