473,388 Members | 1,342 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,388 software developers and data experts.

Find start and end of consecutive dates

3
I am trying to develop a query that will display the start and end dates of a series of dates. My data includes a field with employee number and a field with dates that these employees are absent. I want to display the employee number, the first date that they are absent and the last date they are absent (which may be the same date if they are only away one day). My data looks like this:

EmpID Date
4772 01/01/09
4772 14/04/09
4772 15/04/09
4772 16/04/09
4772 17/04/09
5382 23/03/09
5382 24/03/09
5382 25/03/09
5382 26/03/09
5382 27/03/09
5395 15/06/09

I want the output of my query to look like this:

EmpID StDate EndDate
4772 01/01/09 01/01/09
4772 14/04/09 17/04/09
5382 23/03/09 27/03/09
5395 15/06/09 15/06/09

Any suggestions about how to do this with an Access Query?

Thanks,
Brad
Oct 9 '08 #1
6 4795
DonRayner
489 Expert 256MB
You might want to look into using something with the "first of" and "last of" settings for the totals.
Oct 9 '08 #2
MOOREB
3
Don,
This just gives me the first and last values of all of the dates for each individual. For example with employee 4772, I get values of 01/01/09 and 17/04/09 instead of two entries for employee 4772 (one for the single day absence on 01/01/09 and one for the four day absence in April)

You might want to look into using something with the "first of" and "last of" settings for the totals.
Oct 9 '08 #3
DonRayner
489 Expert 256MB
So let me get this straight.

You want to ouput a start date and end date for each time you have either one day by itself or more than one consecutive day. So if somebody is out on say, july 3, 4, 5, 17,18 29 then the output would be like this

ID Start End
1234 06/03/08 06/05/08
1234 06/17/08 06/18/08
1234 06/29/08 06/29/08

If this is what your after, I can't see any way to do it without doing it in VBA, but maybe someone else will know.
Oct 9 '08 #4
MOOREB
3
Exactly. I think your suggestion put me on the path to finding a possible answer. I included a calculated field for "Weeknumber" (Format([Date],"ww")) in my original table and used it to further group my dates before finding the first and last date within that week. I'm not sure its going to work perfectly for me, as I want to track people who take time off over weekends as well but I may get there yet....

Anyone have any further suggestions?

So let me get this straight.

You want to ouput a start date and end date for each time you have either one day by itself or more than one consecutive day. So if somebody is out on say, july 3, 4, 5, 17,18 29 then the output would be like this

ID Start End
1234 06/03/08 06/05/08
1234 06/17/08 06/18/08
1234 06/29/08 06/29/08

If this is what your after, I can't see any way to do it without doing it in VBA, but maybe someone else will know.
Oct 9 '08 #5
NeoPa
32,556 Expert Mod 16PB
I suspect you will need to resort to VBA for this. SQL has no concept of previous and subsequent records.

I certainly see no way to group by the groupings you want (contiguous dates).
Oct 12 '08 #6
Stewart Ross
2,545 Expert Mod 2GB
Hi. NeoPa and DonRayner have given you very good advice regarding the non-positional nature of SQL and the potential use of VBA.

A further observation: the data you posted in post # 1 indicates that you are apparently not recording one crucial piece of information in your staff absence table that you really need - the end date of the absence.

Every employee absence has a start date and an associated end date. These may, as you said in post 1, be the same date - but you need to know them both to calculate (for example) the absence duration in days.

I'd suggest that if you don't record the two dates separately at present you really should do so. How else can you know whether an employee's absence is ongoing (where there is a start date but no end date listed), or how many periods of absence have been taken in a defined period of time?

I attach a screenshot of part of an absence recording form from an HR application of mine which shows the principle.

-Stewart
Attached Images
File Type: jpg ScreenHunter_74.jpg (19.6 KB, 463 views)
Oct 13 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Simon Harris | last post by:
Hi All, Ok - I'll confess from the start, this is more about application logic that ASP, being an ASP programmer, I guessed you people might be able to help! :) I have built a room bookings...
15
by: plaztik8 | last post by:
Hello, Can someone please help me with a query? The table looks like this: BookedRooms =========== CustomerID RoomID BookDateID
8
by: MLH | last post by:
Anybody's solution would be appreciated. Pls, do not pause to write anything for this. I'm not looking for that kind of a handout. I have an idea about how to do it, but I wanted to see if anyone...
17
by: Justin Emlay | last post by:
I'm hopping someone can help me out on a payroll project I need to implement. To start we are dealing with payroll periods. So we are dealing with an exact 10 days (Monday - Friday, 2 weeks). ...
18
by: dfetrow410 | last post by:
Anyone have some code that will do this? Dave
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 ...
2
by: TroyB | last post by:
I am trying to be able to get report of all "employees" that have had 5 consecutive days off from a "date" field in a current table. Normally I would do this by adding the sum of two dates,...
1
by: Mike | last post by:
Hi All, I'm using vb.net as my codebehind lang. and the following code is being executed in my aspx.vb page to stamp a DB row. Dim oStatsInfo As New StatsInfo(CartID, Batch, Set, Num, 0, 0, 0,...
23
by: tkpmep | last post by:
I have a list that starts with zeros, has sporadic data, and then has good data. I define the point at which the data turns good to be the first index with a non-zero entry that is followed by at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.