Solved

Query Min and difference

Posted on 2013-06-06
3
276 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

856 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