USP_MKTMARKETINGPLANBRIEF_MOVEUP

Executes the "Marketing Plan Segment Summary: Move Up" record operation.

Parameters

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

Definition

Copy


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

  declare @PLANITEMID uniqueidentifier;
  declare @SEQ integer;
  declare @TOPBRIEFID uniqueidentifier;

  if @CHANGEAGENTID is null
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

  begin try
    select
      @PLANITEMID = [MARKETINGPLANITEMID],
      @SEQ = [SEQUENCE]
    from
      dbo.[MKTMARKETINGPLANBRIEF] 
    where
      [ID] = @ID;

    if @SEQ > 1
    begin
      --Get the top brief ID

      select
        @TOPBRIEFID = [ID]
      from
        dbo.[MKTMARKETINGPLANBRIEF]
      where
        [MARKETINGPLANITEMID] = @PLANITEMID
      and
        [SEQUENCE] = (@SEQ - 1);

      --Swap the segment summaries

      exec dbo.[USP_MKTMARKETINGPLANBRIEF_SWAPBRIEFS] @TOPBRIEFID, @ID, @CHANGEAGENTID;
    end
  end try
  begin catch
    exec dbo.USP_RAISE_ERROR;
    return 1;
  end catch

  return 0;