Hello friends,
I'm using sql server 2008 r2 and I have a table called attendance with the following fields
attendance_no int
attendance_date date
attendance_timein time(7)
attendance_timeout time(7)
emp_id int
and another table called employee with the following fields
emp_id int
emp_name varchar(50)
emp_tel varchar(50)
I need to calculate the total minutes worked as well as total hours worked for each employee with in a specified date range and I created the below query which working fine but it is not calculating the fractions of hours, I mean when an employee works for example 7 and half hours, its showing just 7 hours instead of 7.5 hours.
SELECT a.attendance_date As 'Date',e.emp_id As 'ID',e.emp_name As 'Name',e.emp_tel As 'Telephone',left(a.attendance_timein,8)[Time in],left(a.attendance_timeout,8)[Time out],
+ CAST(DATEDIFF(second, attendance_timein, attendance_timeout) / 60 AS NVARCHAR(50)) As 'Total minutes',
CAST(DATEDIFF(second,attendance_timein,attendance_timeout) / 60 /60 % 60 AS NVARCHAR(50)) As 'Total hours'
from attendance a join employee e on e.emp_id=a.emp_id and a.attendance_date between '2014-11-06' and '2014-11-08' and e.emp_tel='65098009'
I would appreciate any help about this.
Thanks in advance
Mohamoud
I'm using sql server 2008 r2 and I have a table called attendance with the following fields
attendance_no int
attendance_date date
attendance_timein time(7)
attendance_timeout time(7)
emp_id int
and another table called employee with the following fields
emp_id int
emp_name varchar(50)
emp_tel varchar(50)
I need to calculate the total minutes worked as well as total hours worked for each employee with in a specified date range and I created the below query which working fine but it is not calculating the fractions of hours, I mean when an employee works for example 7 and half hours, its showing just 7 hours instead of 7.5 hours.
SELECT a.attendance_date As 'Date',e.emp_id As 'ID',e.emp_name As 'Name',e.emp_tel As 'Telephone',left(a.attendance_timein,8)[Time in],left(a.attendance_timeout,8)[Time out],
+ CAST(DATEDIFF(second, attendance_timein, attendance_timeout) / 60 AS NVARCHAR(50)) As 'Total minutes',
CAST(DATEDIFF(second,attendance_timein,attendance_timeout) / 60 /60 % 60 AS NVARCHAR(50)) As 'Total hours'
from attendance a join employee e on e.emp_id=a.emp_id and a.attendance_date between '2014-11-06' and '2014-11-08' and e.emp_tel='65098009'
I would appreciate any help about this.
Thanks in advance
Mohamoud