Solved

Query Min and difference

Posted on 2013-06-06
3
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 25

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

632 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