How can I add the hours in a period of 1 month, starting from an Initial date and a Final date in such a way that the result is as follows:
Code fechaActual idClave nombre HorasTotalesMes
2300 2017-12 14290 NombreUsuario 37
The current query that I am executing is the following:
select c.CodeCompany,
CONVERT(char(6), GETDATE(), 112) AS fechaActual,
a.idClave,
c.nombre + ' ' + c.apellidos as Nombre,
d.Descripcion as Depto,
CONVERT(VARCHAR(20),fechaEntrada,108) AS fechaEntrada,
CONVERT(VARCHAR(20),fechaSalida,108) AS fechaSalida,
DATEDIFF(HOUR, fechaEntrada, fechaSalida) %24 AS sumaHoras
from tblasistencia a JOIN tblpersonal c ON a.idClave=c.idClave
JOIN tblDepto d ON c.fkDepto=d.idDepto
where
fechaEntrada BETWEEN CONVERT(DATETIME, '2017-11-01 00:00:00',103) and
CONVERT(DATETIME,'2017-11-30 23:59:59',103)
However, this query shows them in the following way:
Code fechaActual idClave nombre HorasTotalesMes
2300 201712 14290 User3 14:03:36 21:35:11 7
2300 201712 14290 User3 13:43:33 21:36:34 8
2300 201712 14290 User3 13:56:38 21:02:15 8
2300 201712 14290 User3 13:54:01 21:37:26 8
2300 201712 14290 User3 06:00:00 00:00:00 6