|
create trigger t_time on Table 1
for insert
as
begin
insert into Table 2 (TIMESPAN)
select datediff (hour, a.CALTIME, b.CALTIME)-if you need to record the date in Table 2, you can add a column here convert (varchar (10), a.CALTIME, 120)
from Table 1 a inner join inserted b
on a.SWITCH = 'On' and b.SWITCH = 'Off'
and convert (varchar (10), a.CALTIME, 120) = convert (varchar (10), b.CALTIME, 120)
end
go |
|