Hello colleagues I have this query that works well to find the difference between two dates in days, hours, minutes and seconds but when I pass it to the trigger it does not work anymore I get a number 4873 I do not know what I'm doing wrong, my column differs It's varchar type.
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