USP_GLOBALCHANGE_MAPMARKETINGPLANTASKOWNERSTOSTAFFMEMBERS

Parameters

Parameter Parameter Type Mode Description
@TASKOWNERS xml IN
@ASOF datetime IN
@NUMBERADDED int INOUT
@NUMBEREDITED int INOUT
@NUMBERDELETED int INOUT
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


CREATE procedure dbo.[USP_GLOBALCHANGE_MAPMARKETINGPLANTASKOWNERSTOSTAFFMEMBERS]
(
  @TASKOWNERS xml,
  @ASOF datetime = null,
  @NUMBERADDED int = 0 output,
  @NUMBEREDITED int = 0 output,
  @NUMBERDELETED int = 0 output,
  @CHANGEAGENTID uniqueidentifier = null
)
as
  set nocount off;

  begin try
    declare @CURRENTDATE datetime = getdate();

    set @NUMBERADDED = 0;
    set @NUMBEREDITED = 0;
    set @NUMBERDELETED = 0;

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

    update dbo.[MKTMARKETINGPLANITEMTASK] set
      [OWNERID] = T.c.value('(TASKOWNERID)[1]','uniqueidentifier'),
      [DATECHANGED] = @CURRENTDATE,
      [CHANGEDBYID] = @CHANGEAGENTID
    from @TASKOWNERS.nodes('/TASKOWNERS/ITEM') T(c)
    where [MKTMARKETINGPLANITEMTASK].[OWNER] = T.c.value('(TASKOWNER)[1]','nvarchar(100)')
    and [MKTMARKETINGPLANITEMTASK].[OWNERID] is null
    and T.c.value('(TASKOWNERID)[1]','uniqueidentifier') is not null;

    set @NUMBEREDITED = @@ROWCOUNT;
  end try

  begin catch
    exec dbo.[USP_RAISE_ERROR];
    return 1;
  end catch

  return 0;