USP_DIRECTMARKETINGEFFORTBATCH_DELETE

Executes the "Direct Marketing Effort Batch: Delete" record operation.

Parameters

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

Definition

Copy


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

  declare @CHILDIDS table([SEGMENTID] uniqueidentifier, [PACKAGEID] uniqueidentifier, [LISTID] uniqueidentifier, [TESTSEGMENTID] uniqueidentifier);

  insert into @CHILDIDS ([SEGMENTID], [PACKAGEID], [LISTID], [TESTSEGMENTID])
    select
      [BATCHDIRECTMARKETINGEFFORTSEGMENTID],
      [BATCHDIRECTMARKETINGEFFORTPACKAGEID],
      [BATCHDIRECTMARKETINGEFFORTLISTID],
      [BATCHDIRECTMARKETINGEFFORTTESTSEGMENTID]
    from dbo.[BATCHDIRECTMARKETINGEFFORT]
    where [BATCHID] = @ID;


  --Delete the batch first to avoid foreign key violations from the child tables...

  exec dbo.[USP_BATCH_DELETE] @ID, @CURRENTAPPUSERID, @CHANGEAGENTID;


  --Cache the context...

    declare @CONTEXTCACHE varbinary(128) = CONTEXT_INFO();
    if @CHANGEAGENTID is not null
        set CONTEXT_INFO @CHANGEAGENTID;

  --Now delete the rows in the child tables...

  delete dbo.[BATCHDIRECTMARKETINGEFFORTSEGMENT]
  where [ID] in (select [SEGMENTID] from @CHILDIDS);

  delete dbo.[BATCHDIRECTMARKETINGEFFORTPACKAGE]
  where [ID] in (select [PACKAGEID] from @CHILDIDS);

  delete dbo.[BATCHDIRECTMARKETINGEFFORTLIST]
  where [ID] in (select [LISTID] from @CHILDIDS where [LISTID] is not null);

  delete dbo.[BATCHDIRECTMARKETINGEFFORTTESTSEGMENT]
  where [ID] in (select [TESTSEGMENTID] from @CHILDIDS where [TESTSEGMENTID] is not null);

  --Reset the context...

    if @CONTEXTCACHE is not null
        set CONTEXT_INFO @CONTEXTCACHE;

  return 0;