I have the following SQL query:
Select DISTINCT Emp.Name + ' '+ Emp.Surname As FullName, RC.ClockIn,
IO.Name, Present = CASE Dir.InOrOut WHEN 'IN' THEN 'Y' WHEN 'OUT' THEN 'N/A' END
FROM Employees Emp, ClockIns RC, InOrOut IO
WHERE Emp.Emp_Id = RC.Emp_ID
AND IO.IO_Id = RC.IO_ID
AND convert(varchar(10), RC.ClockIn, 111) >= '2010/10/20'
AND convert(varchar(10), RC.ClockIn, 111) <= '2010/10/27'
The result is displayed as follows:
FullName ClockIn Name Present
Person1 2010-01-05 08:30:30 IN Y
Person1 2010-01-05 10:00:00 IN Y
Person1 2010-01-05 11:23:21 IN Y
Person1 2010-01-05 17:00:00 OUT N/A
Person2 2010-01-05 07:58:10 IN Y
Person2 2010-01-05 12:15:48 IN Y
Person3 2010-01-05 16:50:00 OUT N/A
I want to write a query to calculate how many hours a person has been at work. As you can see with the results, I need to find the first time the person logged in, and then find the las time the person logged out, and calculate the difference in time.
any ideas on how to do this?