USP_ITINERARYRESOURCE_GETRESOURCES_UPDATEFROMXML
Used to update a set of records defined by UFN_ITINERARYRESOURCE_GETRESOURCES from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ITINERARYID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 4/29/2010 7:30:48 PM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.6.1444.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_ITINERARYRESOURCE_GETRESOURCES_UPDATEFROMXML
(
@ITINERARYID 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 (
[ID] uniqueidentifier,
[PERTICKETDIVISOR] int,
[PERTICKETQUANTITY] int,
[PRICE] money,
[PRICINGSTRUCTURECODE] tinyint,
[QUANTITYNEEDED] int,
[RESOURCEID] uniqueidentifier)
insert into @TempTbl select
[ID],
[PERTICKETDIVISOR],
[PERTICKETQUANTITY],
[PRICE],
[PRICINGSTRUCTURECODE],
[QUANTITYNEEDED],
[RESOURCEID]
from dbo.UFN_ITINERARYRESOURCE_GETRESOURCES_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.[ITINERARYRESOURCE] where [ITINERARYRESOURCE].ID in
(select ID from dbo.UFN_ITINERARYRESOURCE_GETRESOURCES
(
@ITINERARYID
)
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 [ITINERARYRESOURCE]
set [ITINERARYRESOURCE].[ID]=temp.[ID],
[ITINERARYRESOURCE].[PERTICKETDIVISOR]=temp.[PERTICKETDIVISOR],
[ITINERARYRESOURCE].[PERTICKETQUANTITY]=temp.[PERTICKETQUANTITY],
[ITINERARYRESOURCE].[PRICE]=temp.[PRICE],
[ITINERARYRESOURCE].[PRICINGSTRUCTURECODE]=temp.[PRICINGSTRUCTURECODE],
[ITINERARYRESOURCE].[QUANTITYNEEDED]=temp.[QUANTITYNEEDED],
[ITINERARYRESOURCE].[RESOURCEID]=temp.[RESOURCEID],
[ITINERARYRESOURCE].CHANGEDBYID = @CHANGEAGENTID,
[ITINERARYRESOURCE].DATECHANGED = @CHANGEDATE
from dbo.[ITINERARYRESOURCE] inner join @TempTbl as [temp] on [ITINERARYRESOURCE].ID = [temp].ID
where ([ITINERARYRESOURCE].[ID]<>temp.[ID]) or
([ITINERARYRESOURCE].[ID] is null and temp.[ID] is not null) or
([ITINERARYRESOURCE].[ID] is not null and temp.[ID] is null) or
([ITINERARYRESOURCE].[PERTICKETDIVISOR]<>temp.[PERTICKETDIVISOR]) or
([ITINERARYRESOURCE].[PERTICKETDIVISOR] is null and temp.[PERTICKETDIVISOR] is not null) or
([ITINERARYRESOURCE].[PERTICKETDIVISOR] is not null and temp.[PERTICKETDIVISOR] is null) or
([ITINERARYRESOURCE].[PERTICKETQUANTITY]<>temp.[PERTICKETQUANTITY]) or
([ITINERARYRESOURCE].[PERTICKETQUANTITY] is null and temp.[PERTICKETQUANTITY] is not null) or
([ITINERARYRESOURCE].[PERTICKETQUANTITY] is not null and temp.[PERTICKETQUANTITY] is null) or
([ITINERARYRESOURCE].[PRICE]<>temp.[PRICE]) or
([ITINERARYRESOURCE].[PRICE] is null and temp.[PRICE] is not null) or
([ITINERARYRESOURCE].[PRICE] is not null and temp.[PRICE] is null) or
([ITINERARYRESOURCE].[PRICINGSTRUCTURECODE]<>temp.[PRICINGSTRUCTURECODE]) or
([ITINERARYRESOURCE].[PRICINGSTRUCTURECODE] is null and temp.[PRICINGSTRUCTURECODE] is not null) or
([ITINERARYRESOURCE].[PRICINGSTRUCTURECODE] is not null and temp.[PRICINGSTRUCTURECODE] is null) or
([ITINERARYRESOURCE].[QUANTITYNEEDED]<>temp.[QUANTITYNEEDED]) or
([ITINERARYRESOURCE].[QUANTITYNEEDED] is null and temp.[QUANTITYNEEDED] is not null) or
([ITINERARYRESOURCE].[QUANTITYNEEDED] is not null and temp.[QUANTITYNEEDED] is null) or
([ITINERARYRESOURCE].[RESOURCEID]<>temp.[RESOURCEID]) or
([ITINERARYRESOURCE].[RESOURCEID] is null and temp.[RESOURCEID] is not null) or
([ITINERARYRESOURCE].[RESOURCEID] is not null and temp.[RESOURCEID] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [ITINERARYRESOURCE]
([ITINERARYID],
[ID],
[PERTICKETDIVISOR],
[PERTICKETQUANTITY],
[PRICE],
[PRICINGSTRUCTURECODE],
[QUANTITYNEEDED],
[RESOURCEID],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @ITINERARYID,
[ID],
[PERTICKETDIVISOR],
[PERTICKETQUANTITY],
[PRICE],
[PRICINGSTRUCTURECODE],
[QUANTITYNEEDED],
[RESOURCEID],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[ITINERARYRESOURCE] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;