USP_MKTLETTERCODE_DELETE

Executes the "Letter: Delete" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.

Definition

Copy


CREATE procedure dbo.[USP_MKTLETTERCODE_DELETE]
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier
)
as
  set nocount on;

  -- check if the letter is in use by a marketing acknowledgement template

  if exists(select *
            from dbo.[MKTACKNOWLEDGEMENTMAILINGTEMPLATERULE]
            inner join dbo.[MKTPACKAGE] on [MKTPACKAGE].[ID] = [MKTACKNOWLEDGEMENTMAILINGTEMPLATERULE].[PACKAGEID]
            where [MKTPACKAGE].[LETTERCODEID] = @ID)
    begin
      raiserror('BBERR_MKTLETTERCODE_DELETE_INUSE', 13, 1);
      return 1;
    end

  -- check if the letter is in use on any MKTREVENUELETTER tables, also check the BBEC table directly for letters manually added to revenue

  if exists(select * from dbo.[V_MKTREVENUELETTER] where [LETTERCODEID] = @ID) or
     exists(select * from dbo.[REVENUELETTER] where [LETTERCODEID] = @ID)
    begin
      raiserror('BBERR_MKTLETTERCODE_DELETE_ASSIGNED', 13, 1);
      return 1;
    end

  if (select [ISSYSTEM] from dbo.[LETTERCODE] where [ID] = @ID) = 1
    begin
      raiserror('BBERR_MKTLETTERCODE_DELETE_ISSYSTEM', 13, 1);
      return 1;
    end

  exec dbo.[USP_LETTERCODE_DELETEBYID_WITHCHANGEAGENTID] @ID, @CHANGEAGENTID;

  return 0;