USP_BATCHEVENT_GETPRICES_2_UPDATEFROMXML

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

Parameters

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

Definition

Copy
/*
Generated by Blackbaud AppFx Platform
Date:  11/30/2010 11:29:29 PM
Assembly Version:  Blackbaud.AppFx.Platform.SqlClr, Version=2.8.2022.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_BATCHEVENT_GETPRICES_2_UPDATEFROMXML 
(
@BATCHEVENTID 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 (
   [AMOUNT] money,
   [COST] money,
   [EVENTREGISTRATIONTYPEID] uniqueidentifier,
   [ID] uniqueidentifier,
   [NAME] nvarchar(100),
   [REGISTRATIONCOUNT] int)

insert into @TempTbl select 
    [AMOUNT],
    [COST],
    [EVENTREGISTRATIONTYPEID],
    [ID],
    [NAME],
    [REGISTRATIONCOUNT] 
from dbo.UFN_BATCHEVENT_GETPRICES_2_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.[BATCHEVENTPRICE] where [BATCHEVENTPRICE].ID in 
    (select ID from dbo.UFN_BATCHEVENT_GETPRICES_2
    (
        @BATCHEVENTID
    )
    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 [BATCHEVENTPRICE]
        set [BATCHEVENTPRICE].[AMOUNT]=temp.[AMOUNT],
        [BATCHEVENTPRICE].[COST]=temp.[COST],
        [BATCHEVENTPRICE].[EVENTREGISTRATIONTYPEID]=temp.[EVENTREGISTRATIONTYPEID],
        [BATCHEVENTPRICE].[ID]=temp.[ID],
        [BATCHEVENTPRICE].[NAME]=temp.[NAME],
        [BATCHEVENTPRICE].[REGISTRATIONCOUNT]=temp.[REGISTRATIONCOUNT],
        [BATCHEVENTPRICE].CHANGEDBYID = @CHANGEAGENTID,
        [BATCHEVENTPRICE].DATECHANGED = @CHANGEDATE

    from dbo.[BATCHEVENTPRICE] inner join @TempTbl as [temp] on [BATCHEVENTPRICE].ID = [temp].ID
    where ([BATCHEVENTPRICE].[AMOUNT]<>temp.[AMOUNT]) or 
        ([BATCHEVENTPRICE].[AMOUNT] is null and temp.[AMOUNT] is not null) or 
        ([BATCHEVENTPRICE].[AMOUNT] is not null and temp.[AMOUNT] is null) or 
        ([BATCHEVENTPRICE].[COST]<>temp.[COST]) or 
        ([BATCHEVENTPRICE].[COST] is null and temp.[COST] is not null) or 
        ([BATCHEVENTPRICE].[COST] is not null and temp.[COST] is null) or 
        ([BATCHEVENTPRICE].[EVENTREGISTRATIONTYPEID]<>temp.[EVENTREGISTRATIONTYPEID]) or 
        ([BATCHEVENTPRICE].[EVENTREGISTRATIONTYPEID] is null and temp.[EVENTREGISTRATIONTYPEID] is not null) or 
        ([BATCHEVENTPRICE].[EVENTREGISTRATIONTYPEID] is not null and temp.[EVENTREGISTRATIONTYPEID] is null) or 
        ([BATCHEVENTPRICE].[ID]<>temp.[ID]) or 
        ([BATCHEVENTPRICE].[ID] is null and temp.[ID] is not null) or 
        ([BATCHEVENTPRICE].[ID] is not null and temp.[ID] is null) or 
        ([BATCHEVENTPRICE].[NAME]<>temp.[NAME]) or 
        ([BATCHEVENTPRICE].[NAME] is null and temp.[NAME] is not null) or 
        ([BATCHEVENTPRICE].[NAME] is not null and temp.[NAME] is null) or 
        ([BATCHEVENTPRICE].[REGISTRATIONCOUNT]<>temp.[REGISTRATIONCOUNT]) or 
        ([BATCHEVENTPRICE].[REGISTRATIONCOUNT] is null and temp.[REGISTRATIONCOUNT] is not null) or 
        ([BATCHEVENTPRICE].[REGISTRATIONCOUNT] is not null and temp.[REGISTRATIONCOUNT] is null)

if @@Error <> 0
    return 3;    

-- insert new items

insert into [BATCHEVENTPRICE] 
    ([BATCHEVENTID], 
    [AMOUNT],
    [COST],
    [EVENTREGISTRATIONTYPEID],
    [ID],
    [NAME],
    [REGISTRATIONCOUNT],                
    ADDEDBYID, 
    CHANGEDBYID, 
    DATEADDED, 
    DATECHANGED)
select @BATCHEVENTID
    [AMOUNT],
    [COST],
    [EVENTREGISTRATIONTYPEID],
    [ID],
    [NAME],
    [REGISTRATIONCOUNT], 
    @CHANGEAGENTID
    @CHANGEAGENTID
    @CHANGEDATE
    @CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[BATCHEVENTPRICE] as data where data.ID = [temp].ID)

if @@Error <> 0
    return 4;

return 0;