Solved

Query Min and difference

Posted on 2013-06-06
3
271 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
Comment Utility
Please let me know if you need any help .
EmployeeDatabaseV3.accdb
0
 
LVL 24

Assisted Solution

by:chaau
chaau earned 150 total points
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now