USP_PLANOUTLINE_STEPS_UPDATEFROMXML

Used to update a set of records defined by UFN_PLANOUTLINE_STEPS from the given xml string.

Parameters

Parameter Parameter Type Mode Description
@PLANOUTLINEID uniqueidentifier IN
@XML xml IN
@CHANGEAGENTID uniqueidentifier IN
@CHANGEDATE datetime IN

Definition

Copy
/*
Generated by Blackbaud AppFx Platform
Date:  12/17/2008 2:12:53 AM
Assembly Version:  Blackbaud.AppFx.Platform.SqlClr, Version=1.7.1271.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_PLANOUTLINE_STEPS_UPDATEFROMXML 
(
@PLANOUTLINEID 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 (
   [DATEOFFSET] int,
   [FUNDRAISERROLECODE] tinyint,
   [ID] uniqueidentifier,
   [INTERACTIONTYPECODEID] uniqueidentifier,
   [OBJECTIVE] nvarchar(100),
   [PROSPECTPLANSTATUSCODEID] uniqueidentifier)

insert into @TempTbl select 
    [DATEOFFSET],
    [FUNDRAISERROLECODE],
    [ID],
    [INTERACTIONTYPECODEID],
    [OBJECTIVE],
    [PROSPECTPLANSTATUSCODEID] 
from dbo.UFN_PLANOUTLINE_STEPS_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.[PLANOUTLINESTEP] where [PLANOUTLINESTEP].ID in 
    (select ID from dbo.UFN_PLANOUTLINE_STEPS
    (
        @PLANOUTLINEID
    )
    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 [PLANOUTLINESTEP]
        set [PLANOUTLINESTEP].[DATEOFFSET]=temp.[DATEOFFSET],
        [PLANOUTLINESTEP].[FUNDRAISERROLECODE]=temp.[FUNDRAISERROLECODE],
        [PLANOUTLINESTEP].[ID]=temp.[ID],
        [PLANOUTLINESTEP].[INTERACTIONTYPECODEID]=temp.[INTERACTIONTYPECODEID],
        [PLANOUTLINESTEP].[OBJECTIVE]=temp.[OBJECTIVE],
        [PLANOUTLINESTEP].[PROSPECTPLANSTATUSCODEID]=temp.[PROSPECTPLANSTATUSCODEID],
        [PLANOUTLINESTEP].CHANGEDBYID = @CHANGEAGENTID,
        [PLANOUTLINESTEP].DATECHANGED = @CHANGEDATE

    from dbo.[PLANOUTLINESTEP] inner join @TempTbl as [temp] on [PLANOUTLINESTEP].ID = [temp].ID
    where ([PLANOUTLINESTEP].[DATEOFFSET]<>temp.[DATEOFFSET]) or 
        ([PLANOUTLINESTEP].[DATEOFFSET] is null and temp.[DATEOFFSET] is not null) or 
        ([PLANOUTLINESTEP].[DATEOFFSET] is not null and temp.[DATEOFFSET] is null) or 
        ([PLANOUTLINESTEP].[FUNDRAISERROLECODE]<>temp.[FUNDRAISERROLECODE]) or 
        ([PLANOUTLINESTEP].[FUNDRAISERROLECODE] is null and temp.[FUNDRAISERROLECODE] is not null) or 
        ([PLANOUTLINESTEP].[FUNDRAISERROLECODE] is not null and temp.[FUNDRAISERROLECODE] is null) or 
        ([PLANOUTLINESTEP].[ID]<>temp.[ID]) or 
        ([PLANOUTLINESTEP].[ID] is null and temp.[ID] is not null) or 
        ([PLANOUTLINESTEP].[ID] is not null and temp.[ID] is null) or 
        ([PLANOUTLINESTEP].[INTERACTIONTYPECODEID]<>temp.[INTERACTIONTYPECODEID]) or 
        ([PLANOUTLINESTEP].[INTERACTIONTYPECODEID] is null and temp.[INTERACTIONTYPECODEID] is not null) or 
        ([PLANOUTLINESTEP].[INTERACTIONTYPECODEID] is not null and temp.[INTERACTIONTYPECODEID] is null) or 
        ([PLANOUTLINESTEP].[OBJECTIVE]<>temp.[OBJECTIVE]) or 
        ([PLANOUTLINESTEP].[OBJECTIVE] is null and temp.[OBJECTIVE] is not null) or 
        ([PLANOUTLINESTEP].[OBJECTIVE] is not null and temp.[OBJECTIVE] is null) or 
        ([PLANOUTLINESTEP].[PROSPECTPLANSTATUSCODEID]<>temp.[PROSPECTPLANSTATUSCODEID]) or 
        ([PLANOUTLINESTEP].[PROSPECTPLANSTATUSCODEID] is null and temp.[PROSPECTPLANSTATUSCODEID] is not null) or 
        ([PLANOUTLINESTEP].[PROSPECTPLANSTATUSCODEID] is not null and temp.[PROSPECTPLANSTATUSCODEID] is null)

if @@Error <> 0
    return 3;    

-- insert new items

insert into [PLANOUTLINESTEP] 
    ([PLANOUTLINEID], 
    [DATEOFFSET],
    [FUNDRAISERROLECODE],
    [ID],
    [INTERACTIONTYPECODEID],
    [OBJECTIVE],
    [PROSPECTPLANSTATUSCODEID],                
    ADDEDBYID, 
    CHANGEDBYID, 
    DATEADDED, 
    DATECHANGED)
select @PLANOUTLINEID
    [DATEOFFSET],
    [FUNDRAISERROLECODE],
    [ID],
    [INTERACTIONTYPECODEID],
    [OBJECTIVE],
    [PROSPECTPLANSTATUSCODEID], 
    @CHANGEAGENTID
    @CHANGEAGENTID
    @CHANGEDATE
    @CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[PLANOUTLINESTEP] as data where data.ID = [temp].ID)

if @@Error <> 0
    return 4;

return 0;