One way is to look at the @@rowcount if you are only concerned about the numbers
DECLARE @PurgeDate AS VARCHAR(20)
DECLARE @ArchiveInserts AS VARCHAR(30)
DECLARE @GLTRdeletes AS VARCHAR(30)
DECLARE @ArchiveInsertCount AS INT
DECLARE @GLTRdeletesCount AS INT
SET @PurgeDate = '04/04/2010'
BEGIN TRAN GLTRpurge
BEGIN TRY
----------------------------------------------------------------------------
-- Archive the records to be purged
----------------------------------------------------------------------------
declare @delcount int=0,@insertcount int=0
SELECT COUNT(*) AS 'GLTR Deletes' FROM GLTR WHERE PostDate <= @PurgeDate AND gltrInterfaceDate IS NOT NULL
select @delcount=@@ROWCOUNT
DELETE FROM GLTR WHERE ID IN (SELECT ID FROM GLTR WHERE PostDate <= @PurgeDate AND gltrInterfaceDate IS NOT NULL)
select @insertcount=@@ROWCOUNT
if (@insertcount<>@delcount)
begin
Raiserror('Count doesn''t match rollbacl it'
end
COMMIT GLTRpurge
END TRY
BEGIN CATCH
ROLLBACK GLTRpurge
SELECT 'The transaction was rolled back'
END CATCH
Satheesh
My Blog | How to ask questions in technical forum
No comments:
Post a Comment