USP_CONSTITUENT_GETSOCIALMEDIAACCOUNTS_UPDATEFROMXML
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@CONSTITUENTID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 9/30/2015 12:58:18 AM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=4.0.153.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_CONSTITUENT_GETSOCIALMEDIAACCOUNTS_UPDATEFROMXML
(
@CONSTITUENTID 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 (
[DONOTCONTACT] bit,
[ID] uniqueidentifier,
[INFOSOURCECODEID] uniqueidentifier,
[SEQUENCE] int,
[SOCIALMEDIAACCOUNTTYPECODEID] uniqueidentifier,
[SOCIALMEDIASERVICEID] uniqueidentifier,
[URL] nvarchar(2047),
[USERID] nvarchar(100))
insert into @TempTbl select
[DONOTCONTACT],
[ID],
[INFOSOURCECODEID],
[SEQUENCE],
[SOCIALMEDIAACCOUNTTYPECODEID],
[SOCIALMEDIASERVICEID],
[URL],
[USERID]
from dbo.UFN_CONSTITUENT_GETSOCIALMEDIAACCOUNTS_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.[SOCIALMEDIAACCOUNT] where [SOCIALMEDIAACCOUNT].ID in
(select ID from dbo.UFN_CONSTITUENT_GETSOCIALMEDIAACCOUNTS
(
@CONSTITUENTID
)
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 [SOCIALMEDIAACCOUNT]
set [SOCIALMEDIAACCOUNT].[DONOTCONTACT]=temp.[DONOTCONTACT],
[SOCIALMEDIAACCOUNT].[ID]=temp.[ID],
[SOCIALMEDIAACCOUNT].[INFOSOURCECODEID]=temp.[INFOSOURCECODEID],
[SOCIALMEDIAACCOUNT].[SEQUENCE]=temp.[SEQUENCE],
[SOCIALMEDIAACCOUNT].[SOCIALMEDIAACCOUNTTYPECODEID]=temp.[SOCIALMEDIAACCOUNTTYPECODEID],
[SOCIALMEDIAACCOUNT].[SOCIALMEDIASERVICEID]=temp.[SOCIALMEDIASERVICEID],
[SOCIALMEDIAACCOUNT].[URL]=temp.[URL],
[SOCIALMEDIAACCOUNT].[USERID]=temp.[USERID],
[SOCIALMEDIAACCOUNT].CHANGEDBYID = @CHANGEAGENTID,
[SOCIALMEDIAACCOUNT].DATECHANGED = @CHANGEDATE
from dbo.[SOCIALMEDIAACCOUNT] inner join @TempTbl as [temp] on [SOCIALMEDIAACCOUNT].ID = [temp].ID
where ([SOCIALMEDIAACCOUNT].[DONOTCONTACT]<>temp.[DONOTCONTACT]) or
([SOCIALMEDIAACCOUNT].[DONOTCONTACT] is null and temp.[DONOTCONTACT] is not null) or
([SOCIALMEDIAACCOUNT].[DONOTCONTACT] is not null and temp.[DONOTCONTACT] is null) or
([SOCIALMEDIAACCOUNT].[ID]<>temp.[ID]) or
([SOCIALMEDIAACCOUNT].[ID] is null and temp.[ID] is not null) or
([SOCIALMEDIAACCOUNT].[ID] is not null and temp.[ID] is null) or
([SOCIALMEDIAACCOUNT].[INFOSOURCECODEID]<>temp.[INFOSOURCECODEID]) or
([SOCIALMEDIAACCOUNT].[INFOSOURCECODEID] is null and temp.[INFOSOURCECODEID] is not null) or
([SOCIALMEDIAACCOUNT].[INFOSOURCECODEID] is not null and temp.[INFOSOURCECODEID] is null) or
([SOCIALMEDIAACCOUNT].[SEQUENCE]<>temp.[SEQUENCE]) or
([SOCIALMEDIAACCOUNT].[SEQUENCE] is null and temp.[SEQUENCE] is not null) or
([SOCIALMEDIAACCOUNT].[SEQUENCE] is not null and temp.[SEQUENCE] is null) or
([SOCIALMEDIAACCOUNT].[SOCIALMEDIAACCOUNTTYPECODEID]<>temp.[SOCIALMEDIAACCOUNTTYPECODEID]) or
([SOCIALMEDIAACCOUNT].[SOCIALMEDIAACCOUNTTYPECODEID] is null and temp.[SOCIALMEDIAACCOUNTTYPECODEID] is not null) or
([SOCIALMEDIAACCOUNT].[SOCIALMEDIAACCOUNTTYPECODEID] is not null and temp.[SOCIALMEDIAACCOUNTTYPECODEID] is null) or
([SOCIALMEDIAACCOUNT].[SOCIALMEDIASERVICEID]<>temp.[SOCIALMEDIASERVICEID]) or
([SOCIALMEDIAACCOUNT].[SOCIALMEDIASERVICEID] is null and temp.[SOCIALMEDIASERVICEID] is not null) or
([SOCIALMEDIAACCOUNT].[SOCIALMEDIASERVICEID] is not null and temp.[SOCIALMEDIASERVICEID] is null) or
([SOCIALMEDIAACCOUNT].[URL]<>temp.[URL]) or
([SOCIALMEDIAACCOUNT].[URL] is null and temp.[URL] is not null) or
([SOCIALMEDIAACCOUNT].[URL] is not null and temp.[URL] is null) or
([SOCIALMEDIAACCOUNT].[USERID]<>temp.[USERID]) or
([SOCIALMEDIAACCOUNT].[USERID] is null and temp.[USERID] is not null) or
([SOCIALMEDIAACCOUNT].[USERID] is not null and temp.[USERID] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [SOCIALMEDIAACCOUNT]
([CONSTITUENTID],
[DONOTCONTACT],
[ID],
[INFOSOURCECODEID],
[SEQUENCE],
[SOCIALMEDIAACCOUNTTYPECODEID],
[SOCIALMEDIASERVICEID],
[URL],
[USERID],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @CONSTITUENTID,
[DONOTCONTACT],
[ID],
[INFOSOURCECODEID],
[SEQUENCE],
[SOCIALMEDIAACCOUNTTYPECODEID],
[SOCIALMEDIASERVICEID],
[URL],
[USERID],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[SOCIALMEDIAACCOUNT] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;