SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
ALTER PROCEDURE dbo.upu_Instance_Delete
@InstanceID int
AS
-- Variables
DECLARE @lCurrentID int
DECLARE @lError int
DECLARE @lInstanceID int
DECLARE @lPreviousID int
--Find Children and kill them all.
BEGIN TRAN trInstanceDelete
SET @lPreviousID = -1
SET @lCurrentID = 0
WHILE (@lCurrentID > @lPreviousID) BEGIN
SET @lPreviousID = @lCurrentID
-- Volgende record ophalen
SELECT @lCurrentID = MIN
(I.InstanceID)
FROM Instance I
WHERE (I.ParentID = @InstanceID)
AND (I.InstanceID >
@lPreviousID)
SET @lError = @@ERROR
IF (@lError <> 0) BEGIN
RAISERROR ('Fout bij ophalen
Instance! Fout: %d', 16, 1, @lError)
ROLLBACK TRAN trInstanceDelete
RETURN (-1)
END
-- Controleren of er een nieuwe gevonden is
SET @lCurrentID = ISNULL (@lCurrentID, 0)
IF ((@lCurrentID > 0) AND (@lCurrentID >
@lPreviousID)) BEGIN
-- Delete children
EXEC upu_Instance_Delete
@InstanceID = @lCurrentID
END
END
DELETE Instance
WHERE (InstanceID = @InstanceID)
SET @lError = @@ERROR
IF (@lError <> 0) BEGIN
RAISERROR ('Fout bij verwijderen instance! Fout:
%d', 16, 1, @lError)
ROLLBACK TRAN trInstanceDelete
RETURN (-1)
END
COMMIT TRAN trInstanceDelete
-- The End
RETURN (0)
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Micha Schopman
Software Engineer
Modern Media, Databankweg 12 M, 3821 AL Amersfoort
Tel 033-4535377, Fax 033-4535388
KvK Amersfoort 39081679, Rabo 39.48.05.380
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]