I have the following stored procedure. Each time I run it, rows are deleted, but not all of them. If I run it a 3 times or so, then all the applicable rows are eventually deleted. The total number of rows needing deletion is only about 3500. Can anyone tell me what I missing? Is there a limitation I do not know about?
Thanks!
Eva
Code:
ALTER PROCEDURE xjr_DeleteCompleteStandardElementCrosswalk
(
@SSet varchar(50),
@SVersion varchar(50),
@DSet varchar(50),
@DVersion varchar(50)
)
AS
BEGIN
declare @SSetID int
declare @DSetID int
SELECT @SSetID = pkStandardSetVersionRowID
FROM tblStandardSetVersions
INNER JOIN tblStandardSets on tblStandardSetVersions.fkStandardSetRowID = tblStandardSets.pkStandardSetRowID
INNER JOIN tblVersions on tblStandardSetVersions.fkVersionRowID = tblVersions.pkVersionRowID
WHERE tblStandardSets.pakStandardSetRowID = @SSet AND tblVersions.pakVersionRowID = @SVersion
SELECT @DSetID = pkStandardSetVersionRowID
FROM tblStandardSetVersions
INNER JOIN tblStandardSets on tblStandardSetVersions.fkStandardSetRowID = tblStandardSets.pkStandardSetRowID
INNER JOIN tblVersions on tblStandardSetVersions.fkVersionRowID = tblVersions.pkVersionRowID
WHERE tblStandardSets.pakStandardSetRowID = @DSet AND tblVersions.pakVersionRowID = @DVersion
DELETE tSEC FROM tblStandardElementCrosswalk tSEC
LEFT JOIN xjrvw_StandardSetVersions vSSV on tSEC.fkStandardElementRowID = vSSV.pkStandardElementRowID
LEFT JOIN xjrvw_StandardSetVersions vDSV on tSEC.fkRelatedStandardElementRowID = vDSV.pkStandardElementRowID
WHERE
(vSSV.pkStandardSetVersionRowID = @SSetID AND vDSV.pkStandardSetVersionRowID = @DSetID)
OR
(vSSV.pkStandardSetVersionRowID = @DSetID AND vDSV.pkStandardSetVersionRowID = @SSetID)
END
Eva