USP_MKTPACKAGECREATIVE_MOVEUP

Executes the "Package Creative: 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_MKTPACKAGECREATIVE_MOVEUP]
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier = null
)
as
  set nocount on;

  declare @PACKAGEID uniqueidentifier;
  declare @SEQ integer;
  declare @CURRENTDATE datetime;

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

  set @CURRENTDATE = getdate();

  begin try
    select
      @PACKAGEID = [PACKAGEID],
      @SEQ = [SEQUENCE]
    from
      dbo.[MKTPACKAGECREATIVE]
    where
      [ID] = @ID;

    if @SEQ > 1
    begin
      set @SEQ = @SEQ - 1;

      --Update the creative above first...

      update
        dbo.[MKTPACKAGECREATIVE]
      set
        [SEQUENCE] = [SEQUENCE] + 1,
        [CHANGEDBYID] = @CHANGEAGENTID,
        [DATECHANGED] = @CURRENTDATE
      where
        [PACKAGEID] = @PACKAGEID
      and
        [SEQUENCE] = @SEQ;

      --Now update the current creative...

      update dbo.[MKTPACKAGECREATIVE] 
      set
        [SEQUENCE] = @SEQ,
        [CHANGEDBYID] = @CHANGEAGENTID,
        [DATECHANGED] = @CURRENTDATE
      where
        [ID] = @ID;
    end
  end try
  begin catch
    exec dbo.USP_RAISE_ERROR;
    return 1;
  end catch

  return 0;