USP_JOURNALENTRYANNOTATIONS_UPDATEFROMXML
Used to update a set of records defined by UFN_JOURNALENTRYANNOTATIONS from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@JOURNALENTRYID | uniqueidentifier | IN | |
@ANNOTATIONTYPECODE | tinyint | IN | |
@ANNOTATIONCATEGORYCODE | tinyint | IN | |
@ACCOUNTSTRUCTUREID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 4/29/2010 7:37:28 PM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.6.1444.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_JOURNALENTRYANNOTATIONS_UPDATEFROMXML
(
@JOURNALENTRYID uniqueidentifier,
@ANNOTATIONTYPECODE tinyint,
@ANNOTATIONCATEGORYCODE tinyint,
@ACCOUNTSTRUCTUREID 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 (
[ACCOUNTSTRUCTUREID] uniqueidentifier,
[ANNOTATIONCATEGORYCODE] tinyint,
[ANNOTATIONTYPECODE] tinyint,
[ID] uniqueidentifier,
[SEQUENCE] int,
[TEXT] nvarchar(4000))
insert into @TempTbl select
[ACCOUNTSTRUCTUREID],
[ANNOTATIONCATEGORYCODE],
[ANNOTATIONTYPECODE],
[ID],
[SEQUENCE],
[TEXT]
from dbo.UFN_JOURNALENTRYANNOTATIONS_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.[JOURNALENTRYANNOTATION] where [JOURNALENTRYANNOTATION].ID in
(select ID from dbo.UFN_JOURNALENTRYANNOTATIONS
(
@JOURNALENTRYID,
@ANNOTATIONTYPECODE,
@ANNOTATIONCATEGORYCODE,
@ACCOUNTSTRUCTUREID
)
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 [JOURNALENTRYANNOTATION]
set [JOURNALENTRYANNOTATION].[ACCOUNTSTRUCTUREID]=temp.[ACCOUNTSTRUCTUREID],
[JOURNALENTRYANNOTATION].[ANNOTATIONCATEGORYCODE]=temp.[ANNOTATIONCATEGORYCODE],
[JOURNALENTRYANNOTATION].[ANNOTATIONTYPECODE]=temp.[ANNOTATIONTYPECODE],
[JOURNALENTRYANNOTATION].[ID]=temp.[ID],
[JOURNALENTRYANNOTATION].[SEQUENCE]=temp.[SEQUENCE],
[JOURNALENTRYANNOTATION].[TEXT]=temp.[TEXT],
[JOURNALENTRYANNOTATION].CHANGEDBYID = @CHANGEAGENTID,
[JOURNALENTRYANNOTATION].DATECHANGED = @CHANGEDATE
from dbo.[JOURNALENTRYANNOTATION] inner join @TempTbl as [temp] on [JOURNALENTRYANNOTATION].ID = [temp].ID
where ([JOURNALENTRYANNOTATION].[ACCOUNTSTRUCTUREID]<>temp.[ACCOUNTSTRUCTUREID]) or
([JOURNALENTRYANNOTATION].[ACCOUNTSTRUCTUREID] is null and temp.[ACCOUNTSTRUCTUREID] is not null) or
([JOURNALENTRYANNOTATION].[ACCOUNTSTRUCTUREID] is not null and temp.[ACCOUNTSTRUCTUREID] is null) or
([JOURNALENTRYANNOTATION].[ANNOTATIONCATEGORYCODE]<>temp.[ANNOTATIONCATEGORYCODE]) or
([JOURNALENTRYANNOTATION].[ANNOTATIONCATEGORYCODE] is null and temp.[ANNOTATIONCATEGORYCODE] is not null) or
([JOURNALENTRYANNOTATION].[ANNOTATIONCATEGORYCODE] is not null and temp.[ANNOTATIONCATEGORYCODE] is null) or
([JOURNALENTRYANNOTATION].[ANNOTATIONTYPECODE]<>temp.[ANNOTATIONTYPECODE]) or
([JOURNALENTRYANNOTATION].[ANNOTATIONTYPECODE] is null and temp.[ANNOTATIONTYPECODE] is not null) or
([JOURNALENTRYANNOTATION].[ANNOTATIONTYPECODE] is not null and temp.[ANNOTATIONTYPECODE] is null) or
([JOURNALENTRYANNOTATION].[ID]<>temp.[ID]) or
([JOURNALENTRYANNOTATION].[ID] is null and temp.[ID] is not null) or
([JOURNALENTRYANNOTATION].[ID] is not null and temp.[ID] is null) or
([JOURNALENTRYANNOTATION].[SEQUENCE]<>temp.[SEQUENCE]) or
([JOURNALENTRYANNOTATION].[SEQUENCE] is null and temp.[SEQUENCE] is not null) or
([JOURNALENTRYANNOTATION].[SEQUENCE] is not null and temp.[SEQUENCE] is null) or
([JOURNALENTRYANNOTATION].[TEXT]<>temp.[TEXT]) or
([JOURNALENTRYANNOTATION].[TEXT] is null and temp.[TEXT] is not null) or
([JOURNALENTRYANNOTATION].[TEXT] is not null and temp.[TEXT] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [JOURNALENTRYANNOTATION]
([JOURNALENTRYID],
[ACCOUNTSTRUCTUREID],
[ANNOTATIONCATEGORYCODE],
[ANNOTATIONTYPECODE],
[ID],
[SEQUENCE],
[TEXT],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @JOURNALENTRYID,
[ACCOUNTSTRUCTUREID],
[ANNOTATIONCATEGORYCODE],
[ANNOTATIONTYPECODE],
[ID],
[SEQUENCE],
[TEXT],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[JOURNALENTRYANNOTATION] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;