USP_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES_UPDATEFROMXML
Used to update a set of records defined by UFN_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@CAMPAIGNPRIORITYID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 8/2/2010 7:12:25 PM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.7.1654.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES_UPDATEFROMXML
(
@CAMPAIGNPRIORITYID 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 (
[CAMPAIGNSUBPRIORITYNAMECODEID] uniqueidentifier,
[CURRENCYEXCHANGERATEID] uniqueidentifier,
[GOAL] money,
[ID] uniqueidentifier,
[ORGANIZATIONAMOUNT] money)
insert into @TempTbl select
[CAMPAIGNSUBPRIORITYNAMECODEID],
[CURRENCYEXCHANGERATEID],
[GOAL],
[ID],
[ORGANIZATIONAMOUNT]
from dbo.UFN_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES_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.[CAMPAIGNSUBPRIORITY] where [CAMPAIGNSUBPRIORITY].ID in
(select ID from dbo.UFN_CAMPAIGNPRIORITY_CAMPAIGNSUBPRIORITIES
(
@CAMPAIGNPRIORITYID
)
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 [CAMPAIGNSUBPRIORITY]
set [CAMPAIGNSUBPRIORITY].[CAMPAIGNSUBPRIORITYNAMECODEID]=temp.[CAMPAIGNSUBPRIORITYNAMECODEID],
[CAMPAIGNSUBPRIORITY].[CURRENCYEXCHANGERATEID]=temp.[CURRENCYEXCHANGERATEID],
[CAMPAIGNSUBPRIORITY].[GOAL]=temp.[GOAL],
[CAMPAIGNSUBPRIORITY].[ID]=temp.[ID],
[CAMPAIGNSUBPRIORITY].[ORGANIZATIONAMOUNT]=temp.[ORGANIZATIONAMOUNT],
[CAMPAIGNSUBPRIORITY].CHANGEDBYID = @CHANGEAGENTID,
[CAMPAIGNSUBPRIORITY].DATECHANGED = @CHANGEDATE
from dbo.[CAMPAIGNSUBPRIORITY] inner join @TempTbl as [temp] on [CAMPAIGNSUBPRIORITY].ID = [temp].ID
where ([CAMPAIGNSUBPRIORITY].[CAMPAIGNSUBPRIORITYNAMECODEID]<>temp.[CAMPAIGNSUBPRIORITYNAMECODEID]) or
([CAMPAIGNSUBPRIORITY].[CAMPAIGNSUBPRIORITYNAMECODEID] is null and temp.[CAMPAIGNSUBPRIORITYNAMECODEID] is not null) or
([CAMPAIGNSUBPRIORITY].[CAMPAIGNSUBPRIORITYNAMECODEID] is not null and temp.[CAMPAIGNSUBPRIORITYNAMECODEID] is null) or
([CAMPAIGNSUBPRIORITY].[CURRENCYEXCHANGERATEID]<>temp.[CURRENCYEXCHANGERATEID]) or
([CAMPAIGNSUBPRIORITY].[CURRENCYEXCHANGERATEID] is null and temp.[CURRENCYEXCHANGERATEID] is not null) or
([CAMPAIGNSUBPRIORITY].[CURRENCYEXCHANGERATEID] is not null and temp.[CURRENCYEXCHANGERATEID] is null) or
([CAMPAIGNSUBPRIORITY].[GOAL]<>temp.[GOAL]) or
([CAMPAIGNSUBPRIORITY].[GOAL] is null and temp.[GOAL] is not null) or
([CAMPAIGNSUBPRIORITY].[GOAL] is not null and temp.[GOAL] is null) or
([CAMPAIGNSUBPRIORITY].[ID]<>temp.[ID]) or
([CAMPAIGNSUBPRIORITY].[ID] is null and temp.[ID] is not null) or
([CAMPAIGNSUBPRIORITY].[ID] is not null and temp.[ID] is null) or
([CAMPAIGNSUBPRIORITY].[ORGANIZATIONAMOUNT]<>temp.[ORGANIZATIONAMOUNT]) or
([CAMPAIGNSUBPRIORITY].[ORGANIZATIONAMOUNT] is null and temp.[ORGANIZATIONAMOUNT] is not null) or
([CAMPAIGNSUBPRIORITY].[ORGANIZATIONAMOUNT] is not null and temp.[ORGANIZATIONAMOUNT] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [CAMPAIGNSUBPRIORITY]
([CAMPAIGNPRIORITYID],
[CAMPAIGNSUBPRIORITYNAMECODEID],
[CURRENCYEXCHANGERATEID],
[GOAL],
[ID],
[ORGANIZATIONAMOUNT],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @CAMPAIGNPRIORITYID,
[CAMPAIGNSUBPRIORITYNAMECODEID],
[CURRENCYEXCHANGERATEID],
[GOAL],
[ID],
[ORGANIZATIONAMOUNT],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[CAMPAIGNSUBPRIORITY] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;