USP_EVENTMANAGEMENTTEMPLATE_GETLEVELS_UPDATEFROMXML

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

Parameters

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

Definition

Copy
/*
Generated by Blackbaud AppFx Platform
Date:  8/2/2010 7:13:24 PM
Assembly Version:  Blackbaud.AppFx.Platform.SqlClr, Version=2.7.1654.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_EVENTMANAGEMENTTEMPLATE_GETLEVELS_UPDATEFROMXML 
(
@EVENTMANAGEMENTTEMPLATEID 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 (
   [HASAPPEALS] bit,
   [HASCAMPAIGNS] bit,
   [HASDOCUMENTATION] bit,
   [HASEXPENSES] bit,
   [HASINVITATIONS] bit,
   [HASJOBOCCURRENCES] bit,
   [HASLODGINGOPTIONS] bit,
   [HASREGISTRANTSANDOPTIONS] bit,
   [HASSPEAKERS] bit,
   [HASTASKSANDCOORDINATORS] bit,
   [ID] uniqueidentifier,
   [LEVEL] int,
   [NAME] nvarchar(100))

insert into @TempTbl select 
    [HASAPPEALS],
    [HASCAMPAIGNS],
    [HASDOCUMENTATION],
    [HASEXPENSES],
    [HASINVITATIONS],
    [HASJOBOCCURRENCES],
    [HASLODGINGOPTIONS],
    [HASREGISTRANTSANDOPTIONS],
    [HASSPEAKERS],
    [HASTASKSANDCOORDINATORS],
    [ID],
    [LEVEL],
    [NAME] 
from dbo.UFN_EVENTMANAGEMENTTEMPLATE_GETLEVELS_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.[EVENTMANAGEMENTLEVELTEMPLATE] where [EVENTMANAGEMENTLEVELTEMPLATE].ID in 
    (select ID from dbo.UFN_EVENTMANAGEMENTTEMPLATE_GETLEVELS
    (
        @EVENTMANAGEMENTTEMPLATEID
    )
    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 [EVENTMANAGEMENTLEVELTEMPLATE]
        set [EVENTMANAGEMENTLEVELTEMPLATE].[HASAPPEALS]=temp.[HASAPPEALS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASCAMPAIGNS]=temp.[HASCAMPAIGNS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASDOCUMENTATION]=temp.[HASDOCUMENTATION],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASEXPENSES]=temp.[HASEXPENSES],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASINVITATIONS]=temp.[HASINVITATIONS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASJOBOCCURRENCES]=temp.[HASJOBOCCURRENCES],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASLODGINGOPTIONS]=temp.[HASLODGINGOPTIONS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASREGISTRANTSANDOPTIONS]=temp.[HASREGISTRANTSANDOPTIONS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASSPEAKERS]=temp.[HASSPEAKERS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[HASTASKSANDCOORDINATORS]=temp.[HASTASKSANDCOORDINATORS],
        [EVENTMANAGEMENTLEVELTEMPLATE].[ID]=temp.[ID],
        [EVENTMANAGEMENTLEVELTEMPLATE].[LEVEL]=temp.[LEVEL],
        [EVENTMANAGEMENTLEVELTEMPLATE].[NAME]=temp.[NAME],
        [EVENTMANAGEMENTLEVELTEMPLATE].CHANGEDBYID = @CHANGEAGENTID,
        [EVENTMANAGEMENTLEVELTEMPLATE].DATECHANGED = @CHANGEDATE

    from dbo.[EVENTMANAGEMENTLEVELTEMPLATE] inner join @TempTbl as [temp] on [EVENTMANAGEMENTLEVELTEMPLATE].ID = [temp].ID
    where ([EVENTMANAGEMENTLEVELTEMPLATE].[HASAPPEALS]<>temp.[HASAPPEALS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASAPPEALS] is null and temp.[HASAPPEALS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASAPPEALS] is not null and temp.[HASAPPEALS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASCAMPAIGNS]<>temp.[HASCAMPAIGNS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASCAMPAIGNS] is null and temp.[HASCAMPAIGNS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASCAMPAIGNS] is not null and temp.[HASCAMPAIGNS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASDOCUMENTATION]<>temp.[HASDOCUMENTATION]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASDOCUMENTATION] is null and temp.[HASDOCUMENTATION] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASDOCUMENTATION] is not null and temp.[HASDOCUMENTATION] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASEXPENSES]<>temp.[HASEXPENSES]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASEXPENSES] is null and temp.[HASEXPENSES] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASEXPENSES] is not null and temp.[HASEXPENSES] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASINVITATIONS]<>temp.[HASINVITATIONS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASINVITATIONS] is null and temp.[HASINVITATIONS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASINVITATIONS] is not null and temp.[HASINVITATIONS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASJOBOCCURRENCES]<>temp.[HASJOBOCCURRENCES]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASJOBOCCURRENCES] is null and temp.[HASJOBOCCURRENCES] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASJOBOCCURRENCES] is not null and temp.[HASJOBOCCURRENCES] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASLODGINGOPTIONS]<>temp.[HASLODGINGOPTIONS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASLODGINGOPTIONS] is null and temp.[HASLODGINGOPTIONS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASLODGINGOPTIONS] is not null and temp.[HASLODGINGOPTIONS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASREGISTRANTSANDOPTIONS]<>temp.[HASREGISTRANTSANDOPTIONS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASREGISTRANTSANDOPTIONS] is null and temp.[HASREGISTRANTSANDOPTIONS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASREGISTRANTSANDOPTIONS] is not null and temp.[HASREGISTRANTSANDOPTIONS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASSPEAKERS]<>temp.[HASSPEAKERS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASSPEAKERS] is null and temp.[HASSPEAKERS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASSPEAKERS] is not null and temp.[HASSPEAKERS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASTASKSANDCOORDINATORS]<>temp.[HASTASKSANDCOORDINATORS]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASTASKSANDCOORDINATORS] is null and temp.[HASTASKSANDCOORDINATORS] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[HASTASKSANDCOORDINATORS] is not null and temp.[HASTASKSANDCOORDINATORS] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[ID]<>temp.[ID]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[ID] is null and temp.[ID] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[ID] is not null and temp.[ID] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[LEVEL]<>temp.[LEVEL]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[LEVEL] is null and temp.[LEVEL] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[LEVEL] is not null and temp.[LEVEL] is null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[NAME]<>temp.[NAME]) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[NAME] is null and temp.[NAME] is not null) or 
        ([EVENTMANAGEMENTLEVELTEMPLATE].[NAME] is not null and temp.[NAME] is null)

if @@Error <> 0
    return 3;    

-- insert new items

insert into [EVENTMANAGEMENTLEVELTEMPLATE] 
    ([EVENTMANAGEMENTTEMPLATEID], 
    [HASAPPEALS],
    [HASCAMPAIGNS],
    [HASDOCUMENTATION],
    [HASEXPENSES],
    [HASINVITATIONS],
    [HASJOBOCCURRENCES],
    [HASLODGINGOPTIONS],
    [HASREGISTRANTSANDOPTIONS],
    [HASSPEAKERS],
    [HASTASKSANDCOORDINATORS],
    [ID],
    [LEVEL],
    [NAME],                
    ADDEDBYID, 
    CHANGEDBYID, 
    DATEADDED, 
    DATECHANGED)
select @EVENTMANAGEMENTTEMPLATEID
    [HASAPPEALS],
    [HASCAMPAIGNS],
    [HASDOCUMENTATION],
    [HASEXPENSES],
    [HASINVITATIONS],
    [HASJOBOCCURRENCES],
    [HASLODGINGOPTIONS],
    [HASREGISTRANTSANDOPTIONS],
    [HASSPEAKERS],
    [HASTASKSANDCOORDINATORS],
    [ID],
    [LEVEL],
    [NAME], 
    @CHANGEAGENTID
    @CHANGEAGENTID
    @CHANGEDATE
    @CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[EVENTMANAGEMENTLEVELTEMPLATE] as data where data.ID = [temp].ID)

if @@Error <> 0
    return 4;

return 0;