Solved

Query Min and difference

Posted on 2013-06-06
3
275 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 350 total points
ID: 39227705
Please let me know if you need any help .
EmployeeDatabaseV3.accdb
0
 
LVL 24

Assisted Solution

by:chaau
chaau earned 150 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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 how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

832 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