USP_MKTMARKETINGPLANBRIEF_DELETE

Executes the "Marketing Plan Segment Summary: 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_MKTMARKETINGPLANBRIEF_DELETE]
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier
)
as
  set nocount on;

  declare @SEGMENTATIONID uniqueidentifier;
  declare @SEQUENCE int;
  declare @CURRENTDATE datetime = getdate();

  --Get the brief sequence

  select
    @SEQUENCE = [SEQUENCE]
  from dbo.[MKTMARKETINGPLANBRIEF]
  where [ID] = @ID;

  --Update the segments in the brief to move them to the root level of the mailing

  update dbo.[MKTSEGMENTATIONSEGMENT] set
    @SEGMENTATIONID = [SEGMENTATIONID],
    [MARKETINGPLANBRIEFID] = null,
    [NEXTBRIEFSEQUENCE] = @SEQUENCE,
    [CHANGEDBYID] = @CHANGEAGENTID,
    [DATECHANGED] = @CURRENTDATE
  where [MARKETINGPLANBRIEFID] = @ID;

  --Update the segments after the brief so any new briefs will be added to the end of the mailing

  update dbo.[MKTSEGMENTATIONSEGMENT] set
    [NEXTBRIEFSEQUENCE] = [NEXTBRIEFSEQUENCE] - 1,
    [CHANGEDBYID] = @CHANGEAGENTID,
    [DATECHANGED] = @CURRENTDATE
  where [SEGMENTATIONID] = @SEGMENTATIONID
  and [NEXTBRIEFSEQUENCE] > @SEQUENCE;

  --Update the brief sequences below the one we are deleting...

  update dbo.[MKTMARKETINGPLANBRIEF] set
    [SEQUENCE] = ([SEQUENCE] - 1),
    [CHANGEDBYID] = @CHANGEAGENTID,
    [DATECHANGED] = @CURRENTDATE
  where [SEQUENCE] > @SEQUENCE;

  --Delete the brief

  exec dbo.[USP_MKTMARKETINGPLANBRIEF_DELETEBYID_WITHCHANGEAGENTID] @ID, @CHANGEAGENTID

  return 0;