USP_MKTMARKETINGPLANITEM_GETBRIEFASSUMPTIONSLIST2_UPDATEFROMXML
Used to update a set of records defined by UFN_MKTMARKETINGPLANITEM_GETBRIEFASSUMPTIONSLIST2 from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@MARKETINGPLANITEMID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 8/17/2011 2:51:01 PM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.91.1535.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_MKTMARKETINGPLANITEM_GETBRIEFASSUMPTIONSLIST2_UPDATEFROMXML
(
@MARKETINGPLANITEMID uniqueidentifier,
@XML xml,
@CHANGEAGENTID uniqueidentifier = null,
@CHANGEDATE datetime = null
)
as
set nocount on;
if @CHANGEAGENTID is null
exec USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output
if @CHANGEDATE is null
set @CHANGEDATE = getdate()
-- build a temporary table containing the values from the XML
declare @TempTbl table (
[BASECURRENCYID] uniqueidentifier,
[BUDGETAMOUNT] money,
[ID] uniqueidentifier,
[MARKETINGPLANID] uniqueidentifier,
[NAME] nvarchar(100),
[QUANTITY] int,
[RESPONSERATEGOAL] decimal(20, 4),
[SEQUENCE] int,
[TOTALREVENUEGOAL] money,
[TOTALTRANSACTIONSGOAL] int)
insert into @TempTbl select
[BASECURRENCYID],
[BUDGETAMOUNT],
[ID],
[MARKETINGPLANID],
[NAME],
[QUANTITY],
[RESPONSERATEGOAL],
[SEQUENCE],
[TOTALREVENUEGOAL],
[TOTALTRANSACTIONSGOAL]
from dbo.UFN_MKTMARKETINGPLANITEM_GETBRIEFASSUMPTIONSLIST2_FROMITEMLISTXML(@XML)
update @TempTbl set ID = newid() where (ID is null) or (ID = '00000000-0000-0000-0000-000000000000');
if @@Error <> 0
return 1;
declare @contextCache varbinary(128);
declare @e int;
-- cache current context information
set @contextCache = CONTEXT_INFO();
-- set CONTEXT_INFO to @CHANGEAGENTID
if not @CHANGEAGENTID is null
set CONTEXT_INFO @CHANGEAGENTID;
-- delete any items that no longer exist in the XML table
delete from dbo.[MKTMARKETINGPLANBRIEF] where [MKTMARKETINGPLANBRIEF].ID in
(select ID from dbo.UFN_MKTMARKETINGPLANITEM_GETBRIEFASSUMPTIONSLIST2
(
@MARKETINGPLANITEMID
)
EXCEPT select ID from @TempTbl)
select @e=@@error;
-- reset CONTEXT_INFO to previous value
if not @contextCache is null
set CONTEXT_INFO @contextCache;
if @e <> 0
return 2;
-- update the items that exist in the XML table and the db
update [MKTMARKETINGPLANBRIEF]
set [MKTMARKETINGPLANBRIEF].[BASECURRENCYID]=temp.[BASECURRENCYID],
[MKTMARKETINGPLANBRIEF].[BUDGETAMOUNT]=temp.[BUDGETAMOUNT],
[MKTMARKETINGPLANBRIEF].[ID]=temp.[ID],
[MKTMARKETINGPLANBRIEF].[MARKETINGPLANID]=temp.[MARKETINGPLANID],
[MKTMARKETINGPLANBRIEF].[NAME]=temp.[NAME],
[MKTMARKETINGPLANBRIEF].[QUANTITY]=temp.[QUANTITY],
[MKTMARKETINGPLANBRIEF].[RESPONSERATEGOAL]=temp.[RESPONSERATEGOAL],
[MKTMARKETINGPLANBRIEF].[SEQUENCE]=temp.[SEQUENCE],
[MKTMARKETINGPLANBRIEF].[TOTALREVENUEGOAL]=temp.[TOTALREVENUEGOAL],
[MKTMARKETINGPLANBRIEF].[TOTALTRANSACTIONSGOAL]=temp.[TOTALTRANSACTIONSGOAL],
[MKTMARKETINGPLANBRIEF].CHANGEDBYID = @CHANGEAGENTID,
[MKTMARKETINGPLANBRIEF].DATECHANGED = @CHANGEDATE
from dbo.[MKTMARKETINGPLANBRIEF] inner join @TempTbl as [temp] on [MKTMARKETINGPLANBRIEF].ID = [temp].ID
where ([MKTMARKETINGPLANBRIEF].[BASECURRENCYID]<>temp.[BASECURRENCYID]) or
([MKTMARKETINGPLANBRIEF].[BASECURRENCYID] is null and temp.[BASECURRENCYID] is not null) or
([MKTMARKETINGPLANBRIEF].[BASECURRENCYID] is not null and temp.[BASECURRENCYID] is null) or
([MKTMARKETINGPLANBRIEF].[BUDGETAMOUNT]<>temp.[BUDGETAMOUNT]) or
([MKTMARKETINGPLANBRIEF].[BUDGETAMOUNT] is null and temp.[BUDGETAMOUNT] is not null) or
([MKTMARKETINGPLANBRIEF].[BUDGETAMOUNT] is not null and temp.[BUDGETAMOUNT] is null) or
([MKTMARKETINGPLANBRIEF].[ID]<>temp.[ID]) or
([MKTMARKETINGPLANBRIEF].[ID] is null and temp.[ID] is not null) or
([MKTMARKETINGPLANBRIEF].[ID] is not null and temp.[ID] is null) or
([MKTMARKETINGPLANBRIEF].[MARKETINGPLANID]<>temp.[MARKETINGPLANID]) or
([MKTMARKETINGPLANBRIEF].[MARKETINGPLANID] is null and temp.[MARKETINGPLANID] is not null) or
([MKTMARKETINGPLANBRIEF].[MARKETINGPLANID] is not null and temp.[MARKETINGPLANID] is null) or
([MKTMARKETINGPLANBRIEF].[NAME]<>temp.[NAME]) or
([MKTMARKETINGPLANBRIEF].[NAME] is null and temp.[NAME] is not null) or
([MKTMARKETINGPLANBRIEF].[NAME] is not null and temp.[NAME] is null) or
([MKTMARKETINGPLANBRIEF].[QUANTITY]<>temp.[QUANTITY]) or
([MKTMARKETINGPLANBRIEF].[QUANTITY] is null and temp.[QUANTITY] is not null) or
([MKTMARKETINGPLANBRIEF].[QUANTITY] is not null and temp.[QUANTITY] is null) or
([MKTMARKETINGPLANBRIEF].[RESPONSERATEGOAL]<>temp.[RESPONSERATEGOAL]) or
([MKTMARKETINGPLANBRIEF].[RESPONSERATEGOAL] is null and temp.[RESPONSERATEGOAL] is not null) or
([MKTMARKETINGPLANBRIEF].[RESPONSERATEGOAL] is not null and temp.[RESPONSERATEGOAL] is null) or
([MKTMARKETINGPLANBRIEF].[SEQUENCE]<>temp.[SEQUENCE]) or
([MKTMARKETINGPLANBRIEF].[SEQUENCE] is null and temp.[SEQUENCE] is not null) or
([MKTMARKETINGPLANBRIEF].[SEQUENCE] is not null and temp.[SEQUENCE] is null) or
([MKTMARKETINGPLANBRIEF].[TOTALREVENUEGOAL]<>temp.[TOTALREVENUEGOAL]) or
([MKTMARKETINGPLANBRIEF].[TOTALREVENUEGOAL] is null and temp.[TOTALREVENUEGOAL] is not null) or
([MKTMARKETINGPLANBRIEF].[TOTALREVENUEGOAL] is not null and temp.[TOTALREVENUEGOAL] is null) or
([MKTMARKETINGPLANBRIEF].[TOTALTRANSACTIONSGOAL]<>temp.[TOTALTRANSACTIONSGOAL]) or
([MKTMARKETINGPLANBRIEF].[TOTALTRANSACTIONSGOAL] is null and temp.[TOTALTRANSACTIONSGOAL] is not null) or
([MKTMARKETINGPLANBRIEF].[TOTALTRANSACTIONSGOAL] is not null and temp.[TOTALTRANSACTIONSGOAL] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [MKTMARKETINGPLANBRIEF]
([MARKETINGPLANITEMID],
[BASECURRENCYID],
[BUDGETAMOUNT],
[ID],
[MARKETINGPLANID],
[NAME],
[QUANTITY],
[RESPONSERATEGOAL],
[SEQUENCE],
[TOTALREVENUEGOAL],
[TOTALTRANSACTIONSGOAL],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @MARKETINGPLANITEMID,
[BASECURRENCYID],
[BUDGETAMOUNT],
[ID],
[MARKETINGPLANID],
[NAME],
[QUANTITY],
[RESPONSERATEGOAL],
[SEQUENCE],
[TOTALREVENUEGOAL],
[TOTALTRANSACTIONSGOAL],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[MKTMARKETINGPLANBRIEF] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;