USP_SURVEYRESPONSE_GETRESPONSES_UPDATEFROMXML
Used to update a set of records defined by UFN_SURVEYRESPONSE_GETRESPONSES from the given xml string.
Parameters
| Parameter | Parameter Type | Mode | Description | 
|---|---|---|---|
| @SURVEYID | uniqueidentifier | IN | |
| @XML | xml | IN | |
| @CHANGEAGENTID | uniqueidentifier | IN | |
| @CHANGEDATE | datetime | IN | 
Definition
 Copy 
                                    /*
Generated by Blackbaud AppFx Platform
Date:  12/17/2008 2:34:25 AM
Assembly Version:  Blackbaud.AppFx.Platform.SqlClr, Version=1.7.1271.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_SURVEYRESPONSE_GETRESPONSES_UPDATEFROMXML 
(
@SURVEYID 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 (
   [BBNCQUESTIONID] int,
   [BBNCRESPONSEID] int,
   [ID] uniqueidentifier,
   [QUESTION] nvarchar(max),
   [RESPONSE] nvarchar(max))
insert into @TempTbl select 
    [BBNCQUESTIONID],
    [BBNCRESPONSEID],
    [ID],
    [QUESTION],
    [RESPONSE] 
from dbo.UFN_SURVEYRESPONSE_GETRESPONSES_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.[SURVEYRESPONSE] where [SURVEYRESPONSE].ID in 
    (select ID from dbo.UFN_SURVEYRESPONSE_GETRESPONSES
    (
        @SURVEYID
    )
    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 [SURVEYRESPONSE]
        set [SURVEYRESPONSE].[BBNCQUESTIONID]=temp.[BBNCQUESTIONID],
        [SURVEYRESPONSE].[BBNCRESPONSEID]=temp.[BBNCRESPONSEID],
        [SURVEYRESPONSE].[ID]=temp.[ID],
        [SURVEYRESPONSE].[QUESTION]=temp.[QUESTION],
        [SURVEYRESPONSE].[RESPONSE]=temp.[RESPONSE],
        [SURVEYRESPONSE].CHANGEDBYID = @CHANGEAGENTID,
        [SURVEYRESPONSE].DATECHANGED = @CHANGEDATE
    from dbo.[SURVEYRESPONSE] inner join @TempTbl as [temp] on [SURVEYRESPONSE].ID = [temp].ID
    where ([SURVEYRESPONSE].[BBNCQUESTIONID]<>temp.[BBNCQUESTIONID]) or 
        ([SURVEYRESPONSE].[BBNCQUESTIONID] is null and temp.[BBNCQUESTIONID] is not null) or 
        ([SURVEYRESPONSE].[BBNCQUESTIONID] is not null and temp.[BBNCQUESTIONID] is null) or 
        ([SURVEYRESPONSE].[BBNCRESPONSEID]<>temp.[BBNCRESPONSEID]) or 
        ([SURVEYRESPONSE].[BBNCRESPONSEID] is null and temp.[BBNCRESPONSEID] is not null) or 
        ([SURVEYRESPONSE].[BBNCRESPONSEID] is not null and temp.[BBNCRESPONSEID] is null) or 
        ([SURVEYRESPONSE].[ID]<>temp.[ID]) or 
        ([SURVEYRESPONSE].[ID] is null and temp.[ID] is not null) or 
        ([SURVEYRESPONSE].[ID] is not null and temp.[ID] is null) or 
        ([SURVEYRESPONSE].[QUESTION]<>temp.[QUESTION]) or 
        ([SURVEYRESPONSE].[QUESTION] is null and temp.[QUESTION] is not null) or 
        ([SURVEYRESPONSE].[QUESTION] is not null and temp.[QUESTION] is null) or 
        ([SURVEYRESPONSE].[RESPONSE]<>temp.[RESPONSE]) or 
        ([SURVEYRESPONSE].[RESPONSE] is null and temp.[RESPONSE] is not null) or 
        ([SURVEYRESPONSE].[RESPONSE] is not null and temp.[RESPONSE] is null)
if @@Error <> 0
    return 3;    
-- insert new items
insert into [SURVEYRESPONSE] 
    ([SURVEYID], 
    [BBNCQUESTIONID],
    [BBNCRESPONSEID],
    [ID],
    [QUESTION],
    [RESPONSE],                
    ADDEDBYID, 
    CHANGEDBYID, 
    DATEADDED, 
    DATECHANGED)
select @SURVEYID, 
    [BBNCQUESTIONID],
    [BBNCRESPONSEID],
    [ID],
    [QUESTION],
    [RESPONSE], 
    @CHANGEAGENTID, 
    @CHANGEAGENTID, 
    @CHANGEDATE, 
    @CHANGEDATE
from @TempTbl as [temp]
where not exists (select ID from dbo.[SURVEYRESPONSE] as data where data.ID = [temp].ID)
if @@Error <> 0
    return 4;
return 0;