Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day,

I am so confused which is the best approach to get employee's (first time in) & (last time out) each day when they have login to our biometrics clock system.

For instance if "Jorge" has a schedule of 8am - 5pm on March 9, 2013
and he logged many times and has a record attendance of: time in at 10:05, 10:10, 10:15 and Time out at : 5:00. 5:30, 5:45

System should only gets "Jorge's" attendance for today like:

Time in: March 9, 2013 - 10:05 am & Time out: March 9, 2013 - 05:45 pm

Emp_name Emp_time Emp_type
Jorge 3/9/2013 10:00 In
Jorge 3/9/2013 10:10 In
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 17:30 Out
Mike 3/9/2013 17:40 Out
Jorge 3/9/2013 10:02 In
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 17:00 Out
Jorge 3/9/2013 10:14 In
Mike 3/9/2013 10:00 In
Mike 3/9/2013 10:10 In
Jorge 3/9/2013 17:00 Out
Mike 3/9/2013 17:30 Out
Jorge 3/9/2013 17:40 Out
Mike 3/9/2013 10:02 In
Mike 3/9/2013 17:00 Out
Mike 3/9/2013 17:00 Out
Mike 3/9/2013 17:00 Out
Jorge 3/9/2013 10:14 In


table name: Raw_Record
Col1 = Emp_name
Col2 = Emp_time
Col3 = Emp_type

Honestly i haven't tried any code because i am still thinking what is the best approach to get (first time in) & (last time out) for each employees attendance record on each day.

An idea from anyone would be very much helpful. thanks in advance.
Posted
Updated 9-Mar-13 5:36am
v3

1 solution

Example for Microsoft SQL Server:
SQL
select distinct
CE.Emp_Name,
(select min(Emp_Time) from Raw_Record As MINCE where MINCE.Emp_Type ='In' and MINCE.Emp_Name=CE.Emp_Name AND CONVERT(varchar(8),MINCE.EMP_TIME,112)=CONVERT(varchar(8),CE.Emp_Time,112)) As MinTime,
(select max(Emp_Time) from Raw_Record As MAXCE where MAXCE.Emp_Type ='Out' and MAXCE.Emp_Name=CE.Emp_name AND CONVERT(varchar(8),MAXCE.EMP_TIME,112)=CONVERT(varchar(8),CE.Emp_Time,112)) As MaxTime
from Raw_Record As CE


MINCE (Minimum ClockEvents) is table_alias for Raw_Record table used in selection of Minimum Time.
MAXCE (Maximum ClockEvents) is table_alias for Raw_Record table used in selection of Maximum Time.
CE (ClockEvents) is table_alias for Raw_Record table used in main SELECT statement.
 
Share this answer
 
v5
Comments
JMAM 9-Mar-13 11:27am    
Hi Mike,

Can you clarify this code assuming we have a database
table name: Raw_Record
Col1 = Emp_name
Col2 = Emp_time
Col3 = Emp_type

Ce.name = Employee Name
Eventtime = Time Record

What is ClockEvents Mince?

Thank you for quick response btw.
Mike Meinz 9-Mar-13 13:26pm    
Updated Solution 1 to use your column and table names.
JMAM 11-Mar-13 11:03am    
Thank you mike. It works perfectly.
Mike Meinz 11-Mar-13 12:09pm    
That's terrific!
JMAM 6-Apr-13 12:58pm    
Hi Mike,

I have a little problem with this current code, Please have a look at this for further details, Your answer are one of the closest have so far.

http://www.codeproject.com/Questions/573570/SelectplusColumnplusforpluseachplusday

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900