日期:2014-05-17 浏览次数:20518 次
ALTER TRIGGER TRIGGER_PREALARM_INSERT ON [A]
FOR INSERT AS
BEGIN
INSERT prealarmTmp
(
itemNodeRecID,
value,
careDateTime,
clientID,
familyNM,
firstNM
)
SELECT
tc.ItemNodeRecID,
tc.Value,
tct.CareDateTime,
tct.ClientID,
mc.ClientFamilyName,
mc.ClientFirstName
FROM Inserted tc
LEFT JOIN CareTimeline tct ON
tc.CareID = tct.CareID
LEFT JOIN ClientData mc ON
mc.ClientID = tct.ClientID
LEFT JOIN prealarmCode yp ON
tc.ItemNodeRecID = yp.itemNodeRecID
WHERE
tc.ModifyState = 1
AND tct.ModifyState = 1
AND (yp.itemType = 1 AND (CAST(tc.Value AS float) < CAST(yp.value1 AS float)
OR CAST(tc.Value AS float) > CAST(yp.value2 AS float))
OR (yp.itemType = 2 AND CAST(tc.Value AS float) = CAST(yp.value3 AS float)))
END
if exists(select 1 from inserted) and not exists(select 1 from deleted) --插入
--.....
if not exists(select 1 from inserted) and exists(select 1 from deleted) --删除
--....
if exists(select 1 from inserted) and exists(select 1 from deleted) --更新
--....