USP_RECORDOPERATION_REGISTRATIONINFORMATIONDELETE

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN
@CHANGEAGENTID uniqueidentifier IN

Definition

Copy


CREATE procedure dbo.USP_RECORDOPERATION_REGISTRATIONINFORMATIONDELETE
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier
)
as begin
    set nocount on;

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

    -- use the system generated delete routine to allow proper recording of the deleting agent

    exec dbo.USP_REGISTRATIONINFORMATION_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;

    begin try
        declare @contextCache varbinary(128) = CONTEXT_INFO();

        set CONTEXT_INFO @CHANGEAGENTID;

        -- Clean up any empty sections

        delete dbo.PROGRAMEVENTREGISTRATIONSECTION    
        from dbo.PROGRAMEVENTREGISTRATIONSECTION
        left outer join dbo.PROGRAMEVENTREGISTRATIONSECTIONREGISTRATIONINFORMATION
            on PROGRAMEVENTREGISTRATIONSECTION.ID = PROGRAMEVENTREGISTRATIONSECTIONREGISTRATIONINFORMATION.PROGRAMEVENTREGISTRATIONSECTIONID
        where PROGRAMEVENTREGISTRATIONSECTIONREGISTRATIONINFORMATION.ID is null;

        if @contextCache is not null
            set CONTEXT_INFO @contextCache;
    end try

    begin catch
        exec dbo.USP_RAISE_ERROR;
        return 1;
    end catch

    return 0;
end