I want to move records from one table (tbConstateringen) to another (tbArcConstateringen) by inserting into the first and then deleting from the second, based on a value in table tbStudies which is linked (1 to many) to table tbAudits, which is linked (1 to many) to table tbConstateringen.
The updating works:
The deleting always removes 0 records:
Any suggestions welcome
The updating works:
Code:
SET IDENTITY_INSERT dbo.tbArcConstateringen ON
INSERT INTO tbArcConstateringen
(
coNummer_i,coTYPE_i,coConstatering,coStatus_i,coWissen_b,coAuditkey,coAntwoord,coKeyfield
)
SELECT
coNummer_i,coTYPE_i,coConstatering,coStatus_i,coWissen_b,coAuditkey,coAntwoord,coKeyfield
FROM dbo.tbConstateringen LEFT OUTER JOIN dbo.tbAudits
ON dbo.tbConstateringen.coAuditkey = dbo.tbAudits.aKeyfield LEFT OUTER JOIN dbo.tbStudies
ON dbo.tbAudits.aStudyKey = dbo.tbStudies.gKeyfield
WHERE (dbo.tbStudies.gKeyfield=@record)
print @@rowcount
SET IDENTITY_INSERT dbo.tbArcConstateringen OFF
The deleting always removes 0 records:
Code:
DELETE tbConstateringen FROM dbo.tbConstateringen LEFT JOIN dbo.tbAudits
ON dbo.tbConstateringen.coAuditkey = dbo.tbAudits.aKeyfield LEFT JOIN dbo.tbStudies
ON dbo.tbAudits.aStudyKey = dbo.tbStudies.gKeyfield
WHERE (dbo.tbStudies.gKeyfield=@record)
print @@rowcount