Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Query Min and difference

Posted on 2013-06-06
3
Medium Priority
?
284 Views
Last Modified: 2013-06-06
Hi There,

I have the attached database and I am working on the ActualVSsched query.  The query puts the InTime from tblClockTime and the InSched from tblEmployeeSchedule on the same view and I am trying to do two things:

1.There are several ClockTimes for each employee for the same day.  So for EG, Francoise clocks in on the 22nd May twice, once at 8:17 and once at 14:46.   I am trying to have the query show only the FIRST time any of the employees clock in for that day. In my example above, the query would only show the record that contains Francoise's clock time of 8:17.  

2. I want to make another field in the query that would subtract the InSched from the InTime but only if the InTime is greater than the InSched.  In plain english, if the employee is late, how late in minutes is that employee?

I am so new to databases that I am at a loss as to where to put this.  Trying to learn!

Any help appreciated.
EmployeeDatabaseV3.accdb
0
Comment
Question by:colin911
3 Comments
 
LVL 16

Accepted Solution

by:
santoshmotwani earned 1400 total points
ID: 39227705
Please let me know if you need any help .
EmployeeDatabaseV3.accdb
0
 
LVL 25

Assisted Solution

by:chaau
chaau earned 600 total points
ID: 39227772
Not a problem.

Create a separate query called InOutTimesForTheDay.
The syntax of it must be:
SELECT tblClockTime.CSid, tblClockTime.ClockDate, Min(tblClockTime.InTime) AS InTime, Max(tblClockTime.OutTime) AS OutTime
FROM tblClockTime
GROUP BY tblClockTime.CSid, tblClockTime.ClockDate;

Open in new window


Modify ActualVSsched to use this query instead of tblClockTime:

SELECT tblEmployee.CSid, tblEmployee.First, tblEmployee.Last, InOutTimesForTheDay.ClockDate, tblEmployeeSchedule.InSched, InOutTimesForTheDay.InTime, IIF( Datediff("n", tblEmployeeSchedule.InSched,InOutTimesForTheDay.InTime ) > 0 , Datediff("n", tblEmployeeSchedule.InSched,InOutTimesForTheDay.InTime ) , "On Time") AS ['Actual Start Time']
FROM (tblEmployee INNER JOIN tblEmployeeSchedule ON tblEmployee.[CSid] = tblEmployeeSchedule.[Csid]) INNER JOIN InOutTimesForTheDay ON tblEmployee.[CSid] = InOutTimesForTheDay.[CSid];

Open in new window


I have modified the database and can upload it, but you will be able to do it yourself using the queries above
0
 

Author Closing Comment

by:colin911
ID: 39227868
Thank you both very much for your help.  Santos, you have the most elegant solution since it is only one query.  Chaau, I am learning so I like the see the alternate approach.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

824 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