1
|
IF EXISTS ( select * from sysobjects where type='tr' AND name='Tgr_TrackCode_StateUpdate')
|
2
|
BEGIN
|
3
|
DROP TRIGGER Tgr_TrackCode_StateUpdate;
|
4
|
END
|
5
|
|
6
|
GO
|
7
|
|
8
|
CREATE TRIGGER Tgr_TrackCode_StateUpdate ON TRC_TrackCode AFTER Update
|
9
|
AS
|
10
|
BEGIN
|
11
|
DECLARE @fromTaskNo varchar(100);
|
12
|
DECLARE @toTaskNo varchar(100);
|
13
|
|
14
|
INSERT INTO TRC_TrackCode_StateRecord (FromTask, ToTask,RTime,IsCancel, JCode, [Level], Status, PackFlag, RID, RCode, ParentJCode, BoxNo, AppendCode, TaskNo, TaskNo1, EquipNo, EquipNo1, EquipNo2, PrintCount, Remark, SourceFlag, ScanNo, ScanNo2, LineName, ActiveBatchNo, ImportBatchNo, PrintBatchNo, PrintBoxNo, AddBy, AddOn, EditBy, EditOn, FlagDelete, BatchNum1, BatchNum2, Fuzzy, SN)
|
15
|
SELECT
|
16
|
de.TaskNo,
|
17
|
ins.TaskNo,
|
18
|
sysdatetime(),
|
19
|
0 IsCancel,
|
20
|
de.JCode, de.[Level], de.Status, de.PackFlag, de.RID, de.RCode, de.ParentJCode, de.BoxNo, de.AppendCode, de.TaskNo, de.TaskNo1, de.EquipNo, de.EquipNo1, de.EquipNo2, de.PrintCount, de.Remark, de.SourceFlag, de.ScanNo, de.ScanNo2, de.LineName, de.ActiveBatchNo, de.ImportBatchNo, de.PrintBatchNo, de.PrintBoxNo, de.AddBy, de.AddOn, de.EditBy, de.EditOn, de.FlagDelete, de.BatchNum1, de.BatchNum2, de.Fuzzy, de.SN
|
21
|
FROM deleted de JOIN inserted ins ON de.JCode = ins.JCode
|
22
|
WHERE de.TaskNo IS NOT NULL
|
23
|
AND ins.TaskNo IS NOT NULL
|
24
|
AND de.TaskNo<>ins.TaskNo;
|
25
|
|
26
|
INSERT INTO TRC_TrackCode_StateRecord (FromTask, ToTask,RTime,IsCancel, JCode, [Level], Status, PackFlag, RID, RCode, ParentJCode, BoxNo, AppendCode, TaskNo, TaskNo1, EquipNo, EquipNo1, EquipNo2, PrintCount, Remark, SourceFlag, ScanNo, ScanNo2, LineName, ActiveBatchNo, ImportBatchNo, PrintBatchNo, PrintBoxNo, AddBy, AddOn, EditBy, EditOn, FlagDelete, BatchNum1, BatchNum2, Fuzzy, SN)
|
27
|
SELECT
|
28
|
de.TaskNo,
|
29
|
ins.TaskNo+'_P4',
|
30
|
sysdatetime(),
|
31
|
0 IsCancel,
|
32
|
de.JCode, de.[Level], de.Status, de.PackFlag, de.RID, de.RCode, de.ParentJCode, de.BoxNo, de.AppendCode, de.TaskNo, de.TaskNo1, de.EquipNo, de.EquipNo1, de.EquipNo2, de.PrintCount, de.Remark, de.SourceFlag, de.ScanNo, de.ScanNo2, de.LineName, de.ActiveBatchNo, de.ImportBatchNo, de.PrintBatchNo, de.PrintBoxNo, de.AddBy, de.AddOn, de.EditBy, de.EditOn, de.FlagDelete, de.BatchNum1, de.BatchNum2, de.Fuzzy, de.SN
|
33
|
FROM deleted de JOIN inserted ins ON de.JCode = ins.JCode
|
34
|
WHERE de.PackFlag not in (1,4,5)
|
35
|
AND ins.PackFlag in (4,5)
|
36
|
AND de.TaskNo=ins.TaskNo
|
37
|
;
|
38
|
|
39
|
END
|
40
|
|
41
|
|
42
|
GO
|