日期:2014-05-17 浏览次数:20437 次
CREATE trigger TransportRecordsInsertTrg
on TransportRecords_FID_1
for insert
AS
declare @MaxTemperature float
declare @MinTemperature float
select @MaxTemperature=m.MaxTemp,@MinTemperature=m.MinTemp from
MonitorRules m inner join inserted i
on m.BarCode=i.BarCode
if i.Temperature >@MaxTemperature or i.Temperature <@MinTemperature
begin
insert into MonitorLog (BarCode,RID,TemMonitor) Values(m.BarCode,m.RID,i.Temperature)
end
RETURN
--試試以下:
CREATE trigger TransportRecordsInsertTrg
on TransportRecords_FID_1
for insert
AS
begin
if EXISTS
(
select *
FROM MonitorRules m
inner join inserted i on m.BarCode=i.BarCode
WHERE i.Temperature >m.MaxTemp or i.Temperature <m.MinTemp
)
begin
insert into MonitorLog (BarCode,RID,TemMonitor)
select m.BarCode,m.RID,i.Temperature
FROM MonitorRules m
inner join inserted i on m.BarCode=i.BarCode
WHERE i.Temperature >m.MaxTemp or i.Temperature <m.MinTemp
end
END
CREATE trigger TransportRecordsInsertTrg
on TransportRecords_FID_1
for insert
AS
declare @MaxTemperature float
declare @MinTemperature float
select @MaxTemperature=m.MaxTemp,@MinTemperature=m.MinTemp from
MonitorRules m inner join inserted i
on m.BarCode=i.BarCode
insert into MonitorLog (BarCode,RID,TemMonitor)
select m.BarCode,m.RID,i.Temperature
from MonitorRules m
inner join inserted i
on m.BarCode=i.BarCode
where i.Temperature >@MaxTemperature or i.Temperature <@MinTemperature
go