Chris Hinds
New member
- Local time
- Today, 15:28
- Joined
- Sep 21, 2012
- Messages
- 4
Hi,
First post but reasonably familiar with Access, nest queries and relational data including on SQL Server.
I have a number of data extracts from an SQL server that export to CSV for use in a tactical reporting solution being used to define requirements for the strategic solution. Due to firewall and other restrictions I cannot query the SQL Server directly for data hence the use of CSV files to interchange into Access. For 95% of the data I have it all relating nicely and working, however one step is giving me heartache. I need to calculate the elapsed time spent doing a particular task by a particular person. Below is a key extract of data from the input CSV Data. Apologies for posting as Text but I can't post image with a 0 post count. Attachment Data.jpg contains a more detailed extract of what the log looks like including the missing entries from the text summary
Log_pk Job_pk Person_pk Action Time
1 a x Start 21-09-2012 19:30:07
4 a x Pause 21-09-2012 19:33:14
7 a x Resume 21-09-2012 19:35:00
9 a x End 21-09-2012 19:35:02
I need to work out the time spent by each person on each job.
Basic system rules:
There are a number of occurrences where more than one instance is present, for example Person A on Job X in the image has a Start, Pause, Resume and End.
Here my query returns four rows of results:
J_pk P_pk Start End Time
a x 21-09-2012 19:30:07 21-09-2012 19:30:07 187
a x 21-09-2012 19:30:07 21-09-2012 19:35:02 295
a x 21-09-2012 19:35:00 21-09-2012 19:33:14 -106
a x 21-09-2012 19:35:00 21-09-2012 19:35:02 2
Here, rows 1 and 4 are "good" data i.e. Start to Pause and Resume to End whilst rows 2 and 3 are "bad" results. I know that I can find the row numbers of the good results in my output by:
Where n is the total number of times someone has worked on a job and i is the number of entries I expect to find from 1 to n e.g for a job with 3 periods of work by someone I will get returned 9 rows of data with good data in rows 1, 5 and 9. I realise I could eliminate negative results in the query but that would also invalidate the equation above - a problem for how I'm currently trying to do things, but maybe not with a different way.
I've tried writing other queries off the data to derive how many pairs of data I have and can successfully derive this answer. How can I use that information to write a True/False field against each row for inclusion in the final calculation?
Alternatively am I barking totally up the wrong tree and the answer is so simple that I'm over thinking it.
Any help will be rewarded with warm thanks, virtual beer and general appreciation.
Many thanks
Chris
P.S. Data and Field names have been changed to protect the guilty.
First post but reasonably familiar with Access, nest queries and relational data including on SQL Server.
I have a number of data extracts from an SQL server that export to CSV for use in a tactical reporting solution being used to define requirements for the strategic solution. Due to firewall and other restrictions I cannot query the SQL Server directly for data hence the use of CSV files to interchange into Access. For 95% of the data I have it all relating nicely and working, however one step is giving me heartache. I need to calculate the elapsed time spent doing a particular task by a particular person. Below is a key extract of data from the input CSV Data. Apologies for posting as Text but I can't post image with a 0 post count. Attachment Data.jpg contains a more detailed extract of what the log looks like including the missing entries from the text summary
Log_pk Job_pk Person_pk Action Time
1 a x Start 21-09-2012 19:30:07
4 a x Pause 21-09-2012 19:33:14
7 a x Resume 21-09-2012 19:35:00
9 a x End 21-09-2012 19:35:02
I need to work out the time spent by each person on each job.
Basic system rules:
- Log_pk is always assigned off the clock
- More than one person can be on a task
- A Start record can be followed by Pause or End
- A Resume record can be followed by Pause or End
- A person can Pause/Resume an unlimited number of times on a job
- If a person is Paused the next time they touch the job they will Resume but if a person has Ended the next time they touch the job it will record Start
- A person does not have to have an End record on a job but any Start or Resume records without completion of some kind (Pause or End) should be discarded from calculations
- Any other records in the log should also be discarded (other actions are also tracked in the log but these four are the only actions of concern)
- Groups by Job_pk
- Then groups by Person_pk
- Returns a Start time (entries that are Like Start or Like Resume)
- Returns an End time (entries that are Like Pause or Like End)
- Calculates the time for that particular row
There are a number of occurrences where more than one instance is present, for example Person A on Job X in the image has a Start, Pause, Resume and End.
Here my query returns four rows of results:
J_pk P_pk Start End Time
a x 21-09-2012 19:30:07 21-09-2012 19:30:07 187
a x 21-09-2012 19:30:07 21-09-2012 19:35:02 295
a x 21-09-2012 19:35:00 21-09-2012 19:33:14 -106
a x 21-09-2012 19:35:00 21-09-2012 19:35:02 2
Here, rows 1 and 4 are "good" data i.e. Start to Pause and Resume to End whilst rows 2 and 3 are "bad" results. I know that I can find the row numbers of the good results in my output by:
Code:
(n*i)-n+i
I've tried writing other queries off the data to derive how many pairs of data I have and can successfully derive this answer. How can I use that information to write a True/False field against each row for inclusion in the final calculation?
Alternatively am I barking totally up the wrong tree and the answer is so simple that I'm over thinking it.
Any help will be rewarded with warm thanks, virtual beer and general appreciation.
Many thanks
Chris
P.S. Data and Field names have been changed to protect the guilty.