Hola compañeros tengo esta consulta que funciona bien para encontrar la diferencia entre dos fechas en dias,horas, minutos y segundos pero al pasarlo al trigger ya no me funciona me sale un numero 4873 no se que estoy haciendo mal, mi columna diferencia es tipo varchar.
select
datediff(second, firstdate, lastdate),
datediff(second, firstdate, lastdate) / 86400 as d,
datediff(second, firstdate, lastdate) / 3600 as h,
(datediff(second, firstdate, lastdate) % 3600) / 60 as m,
(datediff(second, firstdate, lastdate) % 3600) % 60 as s
from tiempos
5145 0 1 25 45
1695 0 0 28 15
4024 0 1 7 4
CREATE TRIGGER TGTIEMPOSRESTADEFECHAS
ON PRUEBAS
AFTER UPDATE
AS BEGIN
UPDATE f
set f.diferencia = datediff(second, f.firstdate, f.lastdate)+
datediff(second, f.firstdate, f.lastdate) / 86400 +
datediff(second, f.firstdate, f.lastdate) / 3600 +
(datediff(second, f.firstdate, f.lastdate) % 3600) +
(datediff(second, f.firstdate, f.lastdate) % 3600)
from inserted i inner join Tiempos f on i.TestID=f.TestID
where f.diferencia is null end
2017-07-04 11:10:58.447 2017-07-04 12:18:02.930 4873