jgoodman00
Programmer
- Jan 23, 2001
- 1,510
I have the following Trigger:
ALTER Trigger ADOPT_INS_TRG1
ON dbo.ADOPT
For Insert
NOT FOR REPLICATION
As
INSERT INTO dbo.tblInspection (RefNo)
SELECT RefNo FROM inserted INNER JOIN tblHierarchy
ON inserted.HierarchyID = tblHierarchy.HierarchyID
WHERE dbo.tblHierarchy.CivilsAsset = 0
INSERT INTO dbo.tblRemarks (RefNo)
SELECT RefNo FROM inserted INNER JOIN tblHierarchy
ON inserted.HierarchyID = tblHierarchy.HierarchyID
WHERE dbo.tblHierarchy.CivilsAsset = 0
DECLARE @sql varchar(100)
SELECT @sql=
'Insert INTO dbo.tblAsset' + dbo.tblHierarchy.FormName + '(RefNoL) ' +
'Values(''' + inserted.RefNo + ''')'
FROM dbo.tblHierarchy JOIN inserted
ON dbo.tblHierarchy.HierarchyID = inserted.HierarchyID
EXEC(@SQL)
This works fine until a 'Civils Asset' is encountered, at which point the program returns the 'another user has modified record...' error.
If I swap the position of the two static insert statements, so that they execute after the dynamic statement, it allows the user to insert records where [CivilsAsset] = 1. However, if the user attempts to insert a record where [CivilsAsset] = 0 it errors, because it cannot make the dynamic insert until the change on the [ADOPT] table has been comitted (FK problem).
Any suggestions? James Goodman MCP
ALTER Trigger ADOPT_INS_TRG1
ON dbo.ADOPT
For Insert
NOT FOR REPLICATION
As
INSERT INTO dbo.tblInspection (RefNo)
SELECT RefNo FROM inserted INNER JOIN tblHierarchy
ON inserted.HierarchyID = tblHierarchy.HierarchyID
WHERE dbo.tblHierarchy.CivilsAsset = 0
INSERT INTO dbo.tblRemarks (RefNo)
SELECT RefNo FROM inserted INNER JOIN tblHierarchy
ON inserted.HierarchyID = tblHierarchy.HierarchyID
WHERE dbo.tblHierarchy.CivilsAsset = 0
DECLARE @sql varchar(100)
SELECT @sql=
'Insert INTO dbo.tblAsset' + dbo.tblHierarchy.FormName + '(RefNoL) ' +
'Values(''' + inserted.RefNo + ''')'
FROM dbo.tblHierarchy JOIN inserted
ON dbo.tblHierarchy.HierarchyID = inserted.HierarchyID
EXEC(@SQL)
This works fine until a 'Civils Asset' is encountered, at which point the program returns the 'another user has modified record...' error.
If I swap the position of the two static insert statements, so that they execute after the dynamic statement, it allows the user to insert records where [CivilsAsset] = 1. However, if the user attempts to insert a record where [CivilsAsset] = 0 it errors, because it cannot make the dynamic insert until the change on the [ADOPT] table has been comitted (FK problem).
Any suggestions? James Goodman MCP