USP_PROSPECTPLAN_PARTICIPANTS_UPDATEFROMXML
Used to update a set of records defined by UFN_PROSPECTPLAN_PARTICIPANTS from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@PROSPECTPLANID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 2/1/2011 9:03:10 AM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.9.1001.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_PROSPECTPLAN_PARTICIPANTS_UPDATEFROMXML
(
@PROSPECTPLANID 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 (
[CONSTITUENTID] uniqueidentifier,
[ID] uniqueidentifier,
[PLANPARTICIPANTROLECODEID] uniqueidentifier)
insert into @TempTbl select
[CONSTITUENTID],
[ID],
[PLANPARTICIPANTROLECODEID]
from dbo.UFN_PROSPECTPLAN_PARTICIPANTS_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.[PLANPARTICIPANT] where [PLANPARTICIPANT].ID in
(select ID from dbo.UFN_PROSPECTPLAN_PARTICIPANTS
(
@PROSPECTPLANID
)
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 [PLANPARTICIPANT]
set [PLANPARTICIPANT].[CONSTITUENTID]=temp.[CONSTITUENTID],
[PLANPARTICIPANT].[ID]=temp.[ID],
[PLANPARTICIPANT].[PLANPARTICIPANTROLECODEID]=temp.[PLANPARTICIPANTROLECODEID],
[PLANPARTICIPANT].CHANGEDBYID = @CHANGEAGENTID,
[PLANPARTICIPANT].DATECHANGED = @CHANGEDATE
from dbo.[PLANPARTICIPANT] inner join @TempTbl as [temp] on [PLANPARTICIPANT].ID = [temp].ID
where ([PLANPARTICIPANT].[CONSTITUENTID]<>temp.[CONSTITUENTID]) or
([PLANPARTICIPANT].[CONSTITUENTID] is null and temp.[CONSTITUENTID] is not null) or
([PLANPARTICIPANT].[CONSTITUENTID] is not null and temp.[CONSTITUENTID] is null) or
([PLANPARTICIPANT].[ID]<>temp.[ID]) or
([PLANPARTICIPANT].[ID] is null and temp.[ID] is not null) or
([PLANPARTICIPANT].[ID] is not null and temp.[ID] is null) or
([PLANPARTICIPANT].[PLANPARTICIPANTROLECODEID]<>temp.[PLANPARTICIPANTROLECODEID]) or
([PLANPARTICIPANT].[PLANPARTICIPANTROLECODEID] is null and temp.[PLANPARTICIPANTROLECODEID] is not null) or
([PLANPARTICIPANT].[PLANPARTICIPANTROLECODEID] is not null and temp.[PLANPARTICIPANTROLECODEID] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [PLANPARTICIPANT]
([PROSPECTPLANID],
[CONSTITUENTID],
[ID],
[PLANPARTICIPANTROLECODEID],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @PROSPECTPLANID,
[CONSTITUENTID],
[ID],
[PLANPARTICIPANTROLECODEID],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[PLANPARTICIPANT] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;