USP_TIMETABLEDAY_GETTIMETABLEDAYPERIODS_UPDATEFROMXML
Used to update a set of records defined by UFN_TIMETABLEDAY_GETTIMETABLEDAYPERIODS from the given xml string.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@TIMETABLEDAYID | uniqueidentifier | IN | |
@XML | xml | IN | |
@CHANGEAGENTID | uniqueidentifier | IN | |
@CHANGEDATE | datetime | IN |
Definition
Copy
/*
Generated by Blackbaud AppFx Platform
Date: 4/29/2010 7:36:43 PM
Assembly Version: Blackbaud.AppFx.Platform.SqlClr, Version=2.6.1444.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_TIMETABLEDAY_GETTIMETABLEDAYPERIODS_UPDATEFROMXML
(
@TIMETABLEDAYID 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 (
[DESCRIPTION] nvarchar(60),
[ENDTIME] char(4),
[ID] uniqueidentifier,
[PERIOD] nvarchar(60),
[STARTTIME] char(4))
insert into @TempTbl select
[DESCRIPTION],
[ENDTIME],
[ID],
[PERIOD],
[STARTTIME]
from dbo.UFN_TIMETABLEDAY_GETTIMETABLEDAYPERIODS_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.[TIMETABLEDAYPERIOD] where [TIMETABLEDAYPERIOD].ID in
(select ID from dbo.UFN_TIMETABLEDAY_GETTIMETABLEDAYPERIODS
(
@TIMETABLEDAYID
)
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 [TIMETABLEDAYPERIOD]
set [TIMETABLEDAYPERIOD].[DESCRIPTION]=temp.[DESCRIPTION],
[TIMETABLEDAYPERIOD].[ENDTIME]=temp.[ENDTIME],
[TIMETABLEDAYPERIOD].[ID]=temp.[ID],
[TIMETABLEDAYPERIOD].[PERIOD]=temp.[PERIOD],
[TIMETABLEDAYPERIOD].[STARTTIME]=temp.[STARTTIME],
[TIMETABLEDAYPERIOD].CHANGEDBYID = @CHANGEAGENTID,
[TIMETABLEDAYPERIOD].DATECHANGED = @CHANGEDATE
from dbo.[TIMETABLEDAYPERIOD] inner join @TempTbl as [temp] on [TIMETABLEDAYPERIOD].ID = [temp].ID
where ([TIMETABLEDAYPERIOD].[DESCRIPTION]<>temp.[DESCRIPTION]) or
([TIMETABLEDAYPERIOD].[DESCRIPTION] is null and temp.[DESCRIPTION] is not null) or
([TIMETABLEDAYPERIOD].[DESCRIPTION] is not null and temp.[DESCRIPTION] is null) or
([TIMETABLEDAYPERIOD].[ENDTIME]<>temp.[ENDTIME]) or
([TIMETABLEDAYPERIOD].[ENDTIME] is null and temp.[ENDTIME] is not null) or
([TIMETABLEDAYPERIOD].[ENDTIME] is not null and temp.[ENDTIME] is null) or
([TIMETABLEDAYPERIOD].[ID]<>temp.[ID]) or
([TIMETABLEDAYPERIOD].[ID] is null and temp.[ID] is not null) or
([TIMETABLEDAYPERIOD].[ID] is not null and temp.[ID] is null) or
([TIMETABLEDAYPERIOD].[PERIOD]<>temp.[PERIOD]) or
([TIMETABLEDAYPERIOD].[PERIOD] is null and temp.[PERIOD] is not null) or
([TIMETABLEDAYPERIOD].[PERIOD] is not null and temp.[PERIOD] is null) or
([TIMETABLEDAYPERIOD].[STARTTIME]<>temp.[STARTTIME]) or
([TIMETABLEDAYPERIOD].[STARTTIME] is null and temp.[STARTTIME] is not null) or
([TIMETABLEDAYPERIOD].[STARTTIME] is not null and temp.[STARTTIME] is null)
if @@Error <> 0
return 3;
-- insert new items
insert into [TIMETABLEDAYPERIOD]
([TIMETABLEDAYID],
[DESCRIPTION],
[ENDTIME],
[ID],
[PERIOD],
[STARTTIME],
ADDEDBYID,
CHANGEDBYID,
DATEADDED,
DATECHANGED)
select @TIMETABLEDAYID,
[DESCRIPTION],
[ENDTIME],
[ID],
[PERIOD],
[STARTTIME],
@CHANGEAGENTID,
@CHANGEAGENTID,
@CHANGEDATE,
@CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[TIMETABLEDAYPERIOD] as data where data.ID = [temp].ID)
if @@Error <> 0
return 4;
return 0;