USP_PROGRAM_DELETE

Executes the "Delete Program" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.

Definition

Copy


        CREATE procedure dbo.USP_PROGRAM_DELETE
        (
            @ID uniqueidentifier,
            @CHANGEAGENTID uniqueidentifier
        )
        as begin
            if @CHANGEAGENTID is null  
                exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

            if exists (select ID from dbo.DAILYSALEITEMPROGRAM where PROGRAMID = @ID)
                raiserror('ERR_PROGRAM_IN_USE_DAILYSALEBUTTON', 13, 1)

            declare @e int;
            declare @contextCache varbinary(128);

            set @contextCache = CONTEXT_INFO();

            if not @CHANGEAGENTID is null
                set CONTEXT_INFO @CHANGEAGENTID

            delete from dbo.PROGRAMEVENTLOCATION 
            where EVENTCONFLICTID in (select ID from dbo.EVENTCONFLICT where PROGRAMID = @ID)

            delete from dbo.EVENTRESOURCE
            where EVENTCONFLICTID in (select ID from dbo.EVENTCONFLICT where PROGRAMID = @ID)

            delete from dbo.EVENTSTAFFRESOURCE
            where EVENTCONFLICTID in (select ID from dbo.EVENTCONFLICT where PROGRAMID = @ID)

      -- LeeCh, Bug#48430,

      -- Delete the event from the program group in the combination

            delete from dbo.PROGRAMGROUPPROGRAM
            where PROGRAMID = @ID

            -- Bug #167845 - Staff resource issue when copying a program with resources and then deleting it.

            delete from dbo.PROGRAMSTAFFRESOURCE
            where PROGRAMID = @ID

            -- Delete any registration information associated with the program

            delete from dbo.PROGRAMEVENTREGISTRATIONSECTION
            where PROGRAMID = @ID;

            delete from dbo.EVENTCONFLICT
            where PROGRAMID = @ID;

            if not @contextCache is null
                set CONTEXT_INFO @contextCache

            select @e=@@error;

            if @e <> 0
                return 2;

            exec USP_PROGRAM_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
            return 0;

        end