延后12小时插入不好處理?可使用job,但要另寫代碼處理。CREATE TRIGGER tr_insert
ON a
FOR INSERT
AS
insert into B(...)
select ...
from inserted A
inner join c on c.Id=A.Id
where getdate()>=C.S1 and getdate()<=C.S2go
ON a
FOR INSERT
AS
insert into B(...)
select ...
from inserted A
inner join c on c.Id=A.Id
where getdate()>=C.S1 and getdate()<=C.S2go
for insert
as
begin
if exits((select into_date from inserted) between (select s1 from c) and (select s2 from c) then
update a set into_date=dateadd(hh,12,into_date)
where Id=inserted.Id
insert into b
select * from a inner join inserted on a.Id=inserted.Id
end
ON a
FOR INSERT
AS
--符合條件的進行插入
insert into B(...)
select ...
from inserted A
inner join c on c.Id=A.Id
where datediff(hh,C.S1 ,getdate())>=0 and datediff(hh,C.S2 ,getdate())<=0 --不符合條件的進行時間更改
update A
set A.into_date =dateadd(hh,12,A.into_date ) --加12小時
from inserted B
inner join A on A.Id=B.Id
inner join c on c.Id=A.Id
where not(datediff(hh,C.S1 ,getdate())>=0 and datediff(hh,C.S2 ,getdate())<=0)go
create trigger tr_insert on a
after insert
as
--更新不匹配的时间
update a set into_date=dateadd(hour,12,a.into_date)
from a
join inserted b on a.id=b.id
join c on b.name=c.name
where convert(varchar(2),b.into_date,108)
between c.s1 and c.s2
insert b(mssage,into_date)
select a.mssage,a.into_date
from a join inserted b on a.id=b.id
go
after insert
as
--更新不匹配的时间
update a set into_date=dateadd(hour,12,a.into_date)
from a
join inserted b on a.id=b.id
join c on .nameid=c.id
where convert(varchar(2),b.into_date,108)
between c.s1 and c.s2
insert b(mssage,into_date)
select a.mssage,a.into_date
from a join inserted b on a.id=b.id