USP_PROSPECTPLAN_STEPSWITHOUTSTATUS_UPDATEFROMXML
Used to update a set of records defined by UFN_PROSPECTPLAN_STEPSWITHOUTSTATUS 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: 12/17/2008 2:12:57 AM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=1.7.1271.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_PROSPECTPLAN_STEPSWITHOUTSTATUS_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 (
[ACTUALDATE] datetime,
[CONSTITUENTID] uniqueidentifier,
[EXPECTEDDATE] datetime,
[FUNDRAISERID] uniqueidentifier,
[ID] uniqueidentifier,
[INTERACTIONTYPECODEID] uniqueidentifier,
[OBJECTIVE] nvarchar(100),
[PLANOUTLINESTEPID] uniqueidentifier,
[PROSPECTPLANSTATUSCODEID] uniqueidentifier)
insert into @TempTbl select
[ACTUALDATE],
[CONSTITUENTID],
[EXPECTEDDATE],
[FUNDRAISERID],
[ID],
[INTERACTIONTYPECODEID],
[OBJECTIVE],
[PLANOUTLINESTEPID],
[PROSPECTPLANSTATUSCODEID]
from dbo.UFN_PROSPECTPLAN_STEPSWITHOUTSTATUS_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.[INTERACTION] where [INTERACTION].ID in
(select ID from dbo.UFN_PROSPECTPLAN_STEPSWITHOUTSTATUS
(
@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 [INTERACTION]
set [INTERACTION].[ACTUALDATE]=temp.[ACTUALDATE],
[INTERACTION].[CONSTITUENTID]=temp.[CONSTITUENTID],
[INTERACTION].[EXPECTEDDATE]=temp.[EXPECTEDDATE],
[INTERACTION].[FUNDRAISERID]=temp.[FUNDRAISERID],
[INTERACTION].[ID]=temp.[ID],
[INTERACTION].[INTERACTIONTYPECODEID]=temp.[INTERACTIONTYPECODEID],
[INTERACTION].[OBJECTIVE]=temp.[OBJECTIVE],
[INTERACTION].[PLANOUTLINESTEPID]=temp.[PLANOUTLINESTEPID],
[INTERACTION].[PROSPECTPLANSTATUSCODEID]=temp.[PROSPECTPLANSTATUSCODEID],
[INTERACTION].CHANGEDBYID = @CHANGEAGENTID,
[INTERACTION].DATECHANGED = @CHANGEDATE
from dbo.[INTERACTION] inner join @TempTbl as [temp] on [INTERACTION].ID = [temp].ID
where ([INTERACTION].[ACTUALDATE]<>temp.[ACTUALDATE]) or
([INTERACTION].[ACTUALDATE] is null and temp.[ACTUALDATE] is not null) or
([INTERACTION].[ACTUALDATE] is not null and temp.[ACTUALDATE] is null) or
([INTERACTION].[CONSTITUENTID]<>temp.[CONSTITUENTID]) or
([INTERACTION].[CONSTITUENTID] is null and temp.[CONSTITUENTID] is not null) or
([INTERACTION].[CONSTITUENTID] is not null and temp.[CONSTITUENTID] is null) or
([INTERACTION].[EXPECTEDDATE]<>temp.[EXPECTEDDATE]) or
([INTERACTION].[EXPECTEDDATE] is null and temp.[EXPECTEDDATE] is not null) or
([INTERACTION].[EXPECTEDDATE] is not null and temp.[EXPECTEDDATE] is null) or
([INTERACTION].[FUNDRAISERID]<>temp.[FUNDRAISERID]) or
([INTERACTION].[FUNDRAISERID] is null and temp.[FUNDRAISERID] is not null) or
([INTERACTION].[FUNDRAISERID] is not null and temp.[FUNDRAISERID] is null) or
([INTERACTION].[ID]<>temp.[ID]) or
([INTERACTION].[ID] is null and temp.[ID] is not null) or
([INTERACTION].[ID] is not null and temp.[ID] is null) or
([INTERACTION].[INTERACTIONTYPECODEID]<>temp.[INTERACTIONTYPECODEID]) or
([INTERACTION].[INTERACTIONTYPECODEID] is null and temp.[INTERACTIONTYPECODEID] is not null) or
([INTERACTION].[INTERACTIONTYPECODEID] is not null and temp.[INTERACTIONTYPECODEID] is null) or
([INTERACTION].[OBJECTIVE]<>temp.[OBJECTIVE]) or
([INTERACTION].[OBJECTIVE] is null and temp.[OBJECTIVE] is not null) or
([INTERACTION].[OBJECTIVE] is not null and temp.[OBJECTIVE] is null) or
([INTERACTION].[PLANOUTLINESTEPID]<>temp.[PLANOUTLINESTEPID]) or
([INTERACTION].[PLANOUTLINESTEPID] is null and temp.[PLANOUTLINESTEPID] is not null) or
([INTERACTION].[PLANOUTLINESTEPID] is not null and temp.[PLANOUTLINESTEPID] is null) or
([INTERACTION].[PROSPECTPLANSTATUSCODEID]<>temp.[PROSPECTPLANSTATUSCODEID]) or
([INTERACTION].[PROSPECTPLANSTATUSCODEID] is null and temp.[PROSPECTPLANSTATUSCODEID] is not null) or
([INTERACTION].[PROSPECTPLANSTATUSCODEID] is not null and temp.[PROSPECTPLANSTATUSCODEID] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [INTERACTION]
([PROSPECTPLANID],
[ACTUALDATE],
[CONSTITUENTID],
[EXPECTEDDATE],
[FUNDRAISERID],
[ID],
[INTERACTIONTYPECODEID],
[OBJECTIVE],
[PLANOUTLINESTEPID],
[PROSPECTPLANSTATUSCODEID],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @PROSPECTPLANID,
[ACTUALDATE],
[CONSTITUENTID],
[EXPECTEDDATE],
[FUNDRAISERID],
[ID],
[INTERACTIONTYPECODEID],
[OBJECTIVE],
[PLANOUTLINESTEPID],
[PROSPECTPLANSTATUSCODEID],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[INTERACTION] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;