TR_BANKACCOUNTDEPOSITCORRECTION_UD
Definition
Copy
CREATE trigger [dbo].[TR_BANKACCOUNTDEPOSITCORRECTION_UD] ON [dbo].[BANKACCOUNTDEPOSITCORRECTION] FOR DELETE NOT FOR REPLICATION AS
BEGIN
SET NOCOUNT ON
-- do not allow to delete posted deposit corrections
if exists(select DELETED.ID from DELETED
inner join dbo.BANKACCOUNTDEPOSIT ON BANKACCOUNTDEPOSIT.ID=DELETED.DEPOSITID
inner join dbo.BANKACCOUNTTRANSACTION on BANKACCOUNTDEPOSIT.ID = BANKACCOUNTTRANSACTION.ID
where BANKACCOUNTTRANSACTION.POSTSTATUSCODE = 0)
begin
RAISERROR ('ERR_DELETE_POSTED_TRANSACTION.', 16, 1)
ROLLBACK TRANSACTION
end
--see if the original deposit is locked - if so, raise an error
if exists(Select DEPOSITID from DELETED INNER JOIN DBO.BANKACCOUNTDEPOSIT ON BANKACCOUNTDEPOSIT.ID=DELETED.DEPOSITID where
DELETED.DEPOSITID is not null AND BANKACCOUNTDEPOSIT.STATUSCODE=0) BEGIN
RAISERROR ('Deposit corrections cannot be removed from locked deposits.', 16, 1)
ROLLBACK
END
END