USP_WPSOCIAL_PROFILES_UPDATEFROMXML
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@WPSOCIALID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 9/30/2015 12:58:13 AM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=4.0.153.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_WPSOCIAL_PROFILES_UPDATEFROMXML
(
@WPSOCIALID 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 (
[COMPANY] nvarchar(100),
[EMAIL] nvarchar(100),
[ID] uniqueidentifier,
[LOCATION] nvarchar(100),
[OCCUPATION] nvarchar(100),
[SEQUENCE] int)
insert into @TempTbl select
[COMPANY],
[EMAIL],
[ID],
[LOCATION],
[OCCUPATION],
[SEQUENCE]
from dbo.UFN_WPSOCIAL_PROFILES_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.[WPSOCIALPROFILE] where [WPSOCIALPROFILE].ID in
(select ID from dbo.UFN_WPSOCIAL_PROFILES
(
@WPSOCIALID
)
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 [WPSOCIALPROFILE]
set [WPSOCIALPROFILE].[COMPANY]=temp.[COMPANY],
[WPSOCIALPROFILE].[EMAIL]=temp.[EMAIL],
[WPSOCIALPROFILE].[ID]=temp.[ID],
[WPSOCIALPROFILE].[LOCATION]=temp.[LOCATION],
[WPSOCIALPROFILE].[OCCUPATION]=temp.[OCCUPATION],
[WPSOCIALPROFILE].[SEQUENCE]=temp.[SEQUENCE],
[WPSOCIALPROFILE].CHANGEDBYID = @CHANGEAGENTID,
[WPSOCIALPROFILE].DATECHANGED = @CHANGEDATE
from dbo.[WPSOCIALPROFILE] inner join @TempTbl as [temp] on [WPSOCIALPROFILE].ID = [temp].ID
where ([WPSOCIALPROFILE].[COMPANY]<>temp.[COMPANY]) or
([WPSOCIALPROFILE].[COMPANY] is null and temp.[COMPANY] is not null) or
([WPSOCIALPROFILE].[COMPANY] is not null and temp.[COMPANY] is null) or
([WPSOCIALPROFILE].[EMAIL]<>temp.[EMAIL]) or
([WPSOCIALPROFILE].[EMAIL] is null and temp.[EMAIL] is not null) or
([WPSOCIALPROFILE].[EMAIL] is not null and temp.[EMAIL] is null) or
([WPSOCIALPROFILE].[ID]<>temp.[ID]) or
([WPSOCIALPROFILE].[ID] is null and temp.[ID] is not null) or
([WPSOCIALPROFILE].[ID] is not null and temp.[ID] is null) or
([WPSOCIALPROFILE].[LOCATION]<>temp.[LOCATION]) or
([WPSOCIALPROFILE].[LOCATION] is null and temp.[LOCATION] is not null) or
([WPSOCIALPROFILE].[LOCATION] is not null and temp.[LOCATION] is null) or
([WPSOCIALPROFILE].[OCCUPATION]<>temp.[OCCUPATION]) or
([WPSOCIALPROFILE].[OCCUPATION] is null and temp.[OCCUPATION] is not null) or
([WPSOCIALPROFILE].[OCCUPATION] is not null and temp.[OCCUPATION] is null) or
([WPSOCIALPROFILE].[SEQUENCE]<>temp.[SEQUENCE]) or
([WPSOCIALPROFILE].[SEQUENCE] is null and temp.[SEQUENCE] is not null) or
([WPSOCIALPROFILE].[SEQUENCE] is not null and temp.[SEQUENCE] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [WPSOCIALPROFILE]
([WPSOCIALID],
[COMPANY],
[EMAIL],
[ID],
[LOCATION],
[OCCUPATION],
[SEQUENCE],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @WPSOCIALID,
[COMPANY],
[EMAIL],
[ID],
[LOCATION],
[OCCUPATION],
[SEQUENCE],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[WPSOCIALPROFILE] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;