USP_MKTSOURCECODE_GETITEMLIST_UPDATEFROMXML
Used to update a set of records defined by UFN_MKTSOURCECODE_GETITEMLIST from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@SOURCECODEID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 12/17/2008 2:32:37 AM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=1.7.1271.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_MKTSOURCECODE_GETITEMLIST_UPDATEFROMXML
(
@SOURCECODEID 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 (
[DELIM] nvarchar(1),
[FORMAT] nvarchar(50),
[ID] uniqueidentifier,
[ITEMTYPECODE] tinyint,
[LENGTH] tinyint,
[NAME] nvarchar(50),
[NOTES] nvarchar(255),
[REGEX] nvarchar(255),
[SAMPLE] nvarchar(10),
[SEQUENCE] int)
insert into @TempTbl select
[DELIM],
[FORMAT],
[ID],
[ITEMTYPECODE],
[LENGTH],
[NAME],
[NOTES],
[REGEX],
[SAMPLE],
[SEQUENCE]
from dbo.UFN_MKTSOURCECODE_GETITEMLIST_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.[MKTSOURCECODEITEM] where [MKTSOURCECODEITEM].ID in
(select ID from dbo.UFN_MKTSOURCECODE_GETITEMLIST
(
@SOURCECODEID
)
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 [MKTSOURCECODEITEM]
set [MKTSOURCECODEITEM].[DELIM]=temp.[DELIM],
[MKTSOURCECODEITEM].[FORMAT]=temp.[FORMAT],
[MKTSOURCECODEITEM].[ID]=temp.[ID],
[MKTSOURCECODEITEM].[ITEMTYPECODE]=temp.[ITEMTYPECODE],
[MKTSOURCECODEITEM].[LENGTH]=temp.[LENGTH],
[MKTSOURCECODEITEM].[NAME]=temp.[NAME],
[MKTSOURCECODEITEM].[NOTES]=temp.[NOTES],
[MKTSOURCECODEITEM].[REGEX]=temp.[REGEX],
[MKTSOURCECODEITEM].[SAMPLE]=temp.[SAMPLE],
[MKTSOURCECODEITEM].[SEQUENCE]=temp.[SEQUENCE],
[MKTSOURCECODEITEM].CHANGEDBYID = @CHANGEAGENTID,
[MKTSOURCECODEITEM].DATECHANGED = @CHANGEDATE
from dbo.[MKTSOURCECODEITEM] inner join @TempTbl as [temp] on [MKTSOURCECODEITEM].ID = [temp].ID
where ([MKTSOURCECODEITEM].[DELIM]<>temp.[DELIM]) or
([MKTSOURCECODEITEM].[DELIM] is null and temp.[DELIM] is not null) or
([MKTSOURCECODEITEM].[DELIM] is not null and temp.[DELIM] is null) or
([MKTSOURCECODEITEM].[FORMAT]<>temp.[FORMAT]) or
([MKTSOURCECODEITEM].[FORMAT] is null and temp.[FORMAT] is not null) or
([MKTSOURCECODEITEM].[FORMAT] is not null and temp.[FORMAT] is null) or
([MKTSOURCECODEITEM].[ID]<>temp.[ID]) or
([MKTSOURCECODEITEM].[ID] is null and temp.[ID] is not null) or
([MKTSOURCECODEITEM].[ID] is not null and temp.[ID] is null) or
([MKTSOURCECODEITEM].[ITEMTYPECODE]<>temp.[ITEMTYPECODE]) or
([MKTSOURCECODEITEM].[ITEMTYPECODE] is null and temp.[ITEMTYPECODE] is not null) or
([MKTSOURCECODEITEM].[ITEMTYPECODE] is not null and temp.[ITEMTYPECODE] is null) or
([MKTSOURCECODEITEM].[LENGTH]<>temp.[LENGTH]) or
([MKTSOURCECODEITEM].[LENGTH] is null and temp.[LENGTH] is not null) or
([MKTSOURCECODEITEM].[LENGTH] is not null and temp.[LENGTH] is null) or
([MKTSOURCECODEITEM].[NAME]<>temp.[NAME]) or
([MKTSOURCECODEITEM].[NAME] is null and temp.[NAME] is not null) or
([MKTSOURCECODEITEM].[NAME] is not null and temp.[NAME] is null) or
([MKTSOURCECODEITEM].[NOTES]<>temp.[NOTES]) or
([MKTSOURCECODEITEM].[NOTES] is null and temp.[NOTES] is not null) or
([MKTSOURCECODEITEM].[NOTES] is not null and temp.[NOTES] is null) or
([MKTSOURCECODEITEM].[REGEX]<>temp.[REGEX]) or
([MKTSOURCECODEITEM].[REGEX] is null and temp.[REGEX] is not null) or
([MKTSOURCECODEITEM].[REGEX] is not null and temp.[REGEX] is null) or
([MKTSOURCECODEITEM].[SAMPLE]<>temp.[SAMPLE]) or
([MKTSOURCECODEITEM].[SAMPLE] is null and temp.[SAMPLE] is not null) or
([MKTSOURCECODEITEM].[SAMPLE] is not null and temp.[SAMPLE] is null) or
([MKTSOURCECODEITEM].[SEQUENCE]<>temp.[SEQUENCE]) or
([MKTSOURCECODEITEM].[SEQUENCE] is null and temp.[SEQUENCE] is not null) or
([MKTSOURCECODEITEM].[SEQUENCE] is not null and temp.[SEQUENCE] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [MKTSOURCECODEITEM]
([SOURCECODEID],
[DELIM],
[FORMAT],
[ID],
[ITEMTYPECODE],
[LENGTH],
[NAME],
[NOTES],
[REGEX],
[SAMPLE],
[SEQUENCE],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @SOURCECODEID,
[DELIM],
[FORMAT],
[ID],
[ITEMTYPECODE],
[LENGTH],
[NAME],
[NOTES],
[REGEX],
[SAMPLE],
[SEQUENCE],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[MKTSOURCECODEITEM] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;