Monday, 21 August 2017

Roll back Commit

ALTER Procedure [dbo].[Bill_Test]
@BillId varchar(50)
As

SET NOCOUNT ON
Begin

DECLARE @intErrorCode INT

if exists (select BillId from Bills where Id=@BillId )
Begin

begin Transaction

--Update calculation table

Update BillMaster
Set
Id=0
where
Id=@BillId

SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM

--Delete Record form Bills table

delete from BillTrans where id=@BillId

SELECT @intErrorCode = @@ERROR
IF (@intErrorCode <> 0) GOTO PROBLEM

COMMIT TRAN

select 0
end
else
Begin
select 1
end

End

PROBLEM:
IF (@intErrorCode <> 0) BEGIN
PRINT 'Error occurred!'
    ROLLBACK TRAN
END




No comments:

Post a Comment