USP_MKTMARKETINGPLANBRIEF_MOVEDOWN

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

  declare @PLANITEMID uniqueidentifier;
  declare @SEQ integer;
  declare @BOTTOMBRIEFID 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 < (select max([SEQUENCE]) from dbo.[MKTMARKETINGPLANBRIEF] where [MARKETINGPLANITEMID] = @PLANITEMID)
    begin
      --Get the bottom brief ID

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

      --Swap the segment summaries

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

  return 0;