Hi @chavarin chuy
Try this query:
DECLARE @YA AS DATETIME = GETDATE()
;with cte as
(
select *
from Datos.dbo.RegistroDeEntradas
cross apply (values (datediff(minute, cast( isnull(nullif([HORA DE ENTRADA], ''), [RETARDO]) as time), cast([HORA DE SALIDA] as time)))) M(m)
where DATEPART(ISO_WEEK, @YA) = NoSem
)
select EMPLEADO,ID,timefromparts(SUM(m) / 60, SUM(m) % 60, 0, 0, 0) as [hours worked]
from cte
group by EMPLEADO,ID;
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.