USP_MEMBERSHIPLEVEL_GETBENEFITS3_UPDATEFROMXML
Used to update a set of records defined by UFN_MEMBERSHIPLEVEL_GETBENEFITS3 from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@MEMBERSHIPLEVELID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 11/30/2010 11:29:23 PM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.8.2022.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_MEMBERSHIPLEVEL_GETBENEFITS3_UPDATEFROMXML
(
@MEMBERSHIPLEVELID 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 (
[BASECURRENCYID] uniqueidentifier,
[BENEFITID] uniqueidentifier,
[DETAILS] nvarchar(255),
[ID] uniqueidentifier,
[ORGANIZATIONEXCHANGERATEID] uniqueidentifier,
[ORGANIZATIONUNITVALUE] money,
[QUANTITY] int,
[SEQUENCE] int,
[UNITVALUE] money,
[USEPERCENT] bit,
[VALUEPERCENT] decimal(20, 2))
insert into @TempTbl select
[BASECURRENCYID],
[BENEFITID],
[DETAILS],
[ID],
[ORGANIZATIONEXCHANGERATEID],
[ORGANIZATIONUNITVALUE],
[QUANTITY],
[SEQUENCE],
[UNITVALUE],
[USEPERCENT],
[VALUEPERCENT]
from dbo.UFN_MEMBERSHIPLEVEL_GETBENEFITS3_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.[MEMBERSHIPLEVELBENEFIT] where [MEMBERSHIPLEVELBENEFIT].ID in
(select ID from dbo.UFN_MEMBERSHIPLEVEL_GETBENEFITS3
(
@MEMBERSHIPLEVELID
)
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 [MEMBERSHIPLEVELBENEFIT]
set [MEMBERSHIPLEVELBENEFIT].[BASECURRENCYID]=temp.[BASECURRENCYID],
[MEMBERSHIPLEVELBENEFIT].[BENEFITID]=temp.[BENEFITID],
[MEMBERSHIPLEVELBENEFIT].[DETAILS]=temp.[DETAILS],
[MEMBERSHIPLEVELBENEFIT].[ID]=temp.[ID],
[MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONEXCHANGERATEID]=temp.[ORGANIZATIONEXCHANGERATEID],
[MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONUNITVALUE]=temp.[ORGANIZATIONUNITVALUE],
[MEMBERSHIPLEVELBENEFIT].[QUANTITY]=temp.[QUANTITY],
[MEMBERSHIPLEVELBENEFIT].[SEQUENCE]=temp.[SEQUENCE],
[MEMBERSHIPLEVELBENEFIT].[UNITVALUE]=temp.[UNITVALUE],
[MEMBERSHIPLEVELBENEFIT].[USEPERCENT]=temp.[USEPERCENT],
[MEMBERSHIPLEVELBENEFIT].[VALUEPERCENT]=temp.[VALUEPERCENT],
[MEMBERSHIPLEVELBENEFIT].CHANGEDBYID = @CHANGEAGENTID,
[MEMBERSHIPLEVELBENEFIT].DATECHANGED = @CHANGEDATE
from dbo.[MEMBERSHIPLEVELBENEFIT] inner join @TempTbl as [temp] on [MEMBERSHIPLEVELBENEFIT].ID = [temp].ID
where ([MEMBERSHIPLEVELBENEFIT].[BASECURRENCYID]<>temp.[BASECURRENCYID]) or
([MEMBERSHIPLEVELBENEFIT].[BASECURRENCYID] is null and temp.[BASECURRENCYID] is not null) or
([MEMBERSHIPLEVELBENEFIT].[BASECURRENCYID] is not null and temp.[BASECURRENCYID] is null) or
([MEMBERSHIPLEVELBENEFIT].[BENEFITID]<>temp.[BENEFITID]) or
([MEMBERSHIPLEVELBENEFIT].[BENEFITID] is null and temp.[BENEFITID] is not null) or
([MEMBERSHIPLEVELBENEFIT].[BENEFITID] is not null and temp.[BENEFITID] is null) or
([MEMBERSHIPLEVELBENEFIT].[DETAILS]<>temp.[DETAILS]) or
([MEMBERSHIPLEVELBENEFIT].[DETAILS] is null and temp.[DETAILS] is not null) or
([MEMBERSHIPLEVELBENEFIT].[DETAILS] is not null and temp.[DETAILS] is null) or
([MEMBERSHIPLEVELBENEFIT].[ID]<>temp.[ID]) or
([MEMBERSHIPLEVELBENEFIT].[ID] is null and temp.[ID] is not null) or
([MEMBERSHIPLEVELBENEFIT].[ID] is not null and temp.[ID] is null) or
([MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONEXCHANGERATEID]<>temp.[ORGANIZATIONEXCHANGERATEID]) or
([MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONEXCHANGERATEID] is null and temp.[ORGANIZATIONEXCHANGERATEID] is not null) or
([MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONEXCHANGERATEID] is not null and temp.[ORGANIZATIONEXCHANGERATEID] is null) or
([MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONUNITVALUE]<>temp.[ORGANIZATIONUNITVALUE]) or
([MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONUNITVALUE] is null and temp.[ORGANIZATIONUNITVALUE] is not null) or
([MEMBERSHIPLEVELBENEFIT].[ORGANIZATIONUNITVALUE] is not null and temp.[ORGANIZATIONUNITVALUE] is null) or
([MEMBERSHIPLEVELBENEFIT].[QUANTITY]<>temp.[QUANTITY]) or
([MEMBERSHIPLEVELBENEFIT].[QUANTITY] is null and temp.[QUANTITY] is not null) or
([MEMBERSHIPLEVELBENEFIT].[QUANTITY] is not null and temp.[QUANTITY] is null) or
([MEMBERSHIPLEVELBENEFIT].[SEQUENCE]<>temp.[SEQUENCE]) or
([MEMBERSHIPLEVELBENEFIT].[SEQUENCE] is null and temp.[SEQUENCE] is not null) or
([MEMBERSHIPLEVELBENEFIT].[SEQUENCE] is not null and temp.[SEQUENCE] is null) or
([MEMBERSHIPLEVELBENEFIT].[UNITVALUE]<>temp.[UNITVALUE]) or
([MEMBERSHIPLEVELBENEFIT].[UNITVALUE] is null and temp.[UNITVALUE] is not null) or
([MEMBERSHIPLEVELBENEFIT].[UNITVALUE] is not null and temp.[UNITVALUE] is null) or
([MEMBERSHIPLEVELBENEFIT].[USEPERCENT]<>temp.[USEPERCENT]) or
([MEMBERSHIPLEVELBENEFIT].[USEPERCENT] is null and temp.[USEPERCENT] is not null) or
([MEMBERSHIPLEVELBENEFIT].[USEPERCENT] is not null and temp.[USEPERCENT] is null) or
([MEMBERSHIPLEVELBENEFIT].[VALUEPERCENT]<>temp.[VALUEPERCENT]) or
([MEMBERSHIPLEVELBENEFIT].[VALUEPERCENT] is null and temp.[VALUEPERCENT] is not null) or
([MEMBERSHIPLEVELBENEFIT].[VALUEPERCENT] is not null and temp.[VALUEPERCENT] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [MEMBERSHIPLEVELBENEFIT]
([MEMBERSHIPLEVELID],
[BASECURRENCYID],
[BENEFITID],
[DETAILS],
[ID],
[ORGANIZATIONEXCHANGERATEID],
[ORGANIZATIONUNITVALUE],
[QUANTITY],
[SEQUENCE],
[UNITVALUE],
[USEPERCENT],
[VALUEPERCENT],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @MEMBERSHIPLEVELID,
[BASECURRENCYID],
[BENEFITID],
[DETAILS],
[ID],
[ORGANIZATIONEXCHANGERATEID],
[ORGANIZATIONUNITVALUE],
[QUANTITY],
[SEQUENCE],
[UNITVALUE],
[USEPERCENT],
[VALUEPERCENT],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[MEMBERSHIPLEVELBENEFIT] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;