USP_DATAFORMTEMPLATE_ADD_SPONSORSHIPREASON

The save procedure used by the add dataform template "Sponsorship Reason Add Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@REASONTYPECODE int IN Type
@REASON nvarchar(100) IN Reason
@TRANSFERSPONSORSFORINELIGIBLECHILD bit IN Transfer sponsors for ineligible child

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_SPONSORSHIPREASON
(
    @ID uniqueidentifier = null output,
    @CHANGEAGENTID uniqueidentifier = null,
  @REASONTYPECODE int=null,
    @REASON nvarchar(100) = null,
    @TRANSFERSPONSORSFORINELIGIBLECHILD bit = null
)
as

set nocount on;

if @ID is null
    set @ID = newid()

if @CHANGEAGENTID is null  
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

if @REASONTYPECODE <> 1 and @REASONTYPECODE<>2
    set @TRANSFERSPONSORSFORINELIGIBLECHILD = 0

begin try
    insert into dbo.SPONSORSHIPREASON
        (ID, REASON, REASONTYPECODE, TRANSFERSPONSORSFORINELIGIBLECHILD, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
    values
        (@ID, @REASON, @REASONTYPECODE, @TRANSFERSPONSORSFORINELIGIBLECHILD, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)

end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0