USP_PROGRAMRESOURCE_GETRESOURCES_ADDFROMXML

Used to add a set of records defined by UFN_PROGRAMRESOURCE_GETRESOURCES from the given xml string.

Parameters

Parameter Parameter Type Mode Description
@PROGRAMID uniqueidentifier IN
@XML xml IN
@CHANGEAGENTID uniqueidentifier IN
@CHANGEDATE datetime IN

Definition

Copy
/*
Generated by Blackbaud AppFx Platform
Date:  1/27/2010 7:26:00 PM
Assembly Version:  Blackbaud.AppFx.Platform.SqlClr, Version=2.5.465.0, Culture=neutral, PublicKeyToken=null
Copyright Blackbaud
*/
CREATE PROCEDURE dbo.USP_PROGRAMRESOURCE_GETRESOURCES_ADDFROMXML 
(
@PROGRAMID 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 (
   [ID] uniqueidentifier,
   [QUANTITYNEEDED] int,
   [RESOURCEID] uniqueidentifier)

insert into @TempTbl select 
    [ID],
    [QUANTITYNEEDED],
    [RESOURCEID] 
from dbo.UFN_PROGRAMRESOURCE_GETRESOURCES_FROMITEMLISTXML(@XML)

update @TempTbl set ID = newid() where (ID is null) or (ID = '00000000-0000-0000-0000-000000000000');

if @@Error <> 0
    return 1;

-- insert new items

insert into [PROGRAMRESOURCE] 
    ([PROGRAMID], 
    [ID],
    [QUANTITYNEEDED],
    [RESOURCEID],                
    ADDEDBYID, 
    CHANGEDBYID, 
    DATEADDED, 
    DATECHANGED)
select @PROGRAMID
    [ID],
    [QUANTITYNEEDED],
    [RESOURCEID], 
    @CHANGEAGENTID
    @CHANGEAGENTID
    @CHANGEDATE
    @CHANGEDATE
from @TempTbl as [temp]

if @@Error <> 0
    return 2;

return 0;