USP_FAFBENEFIT_DELETE

Executes the "FAFBenefit: Delete" 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_FAFBENEFIT_DELETE(@ID uniqueidentifier, @CHANGEAGENTID uniqueidentifier)
as begin
    set nocount on;
    --check deletion rules, if any                

    if (select count(*) from dbo.APPEALBENEFITDETAIL where BENEFITID = @ID) > 0
    begin
        raiserror('This benefit is associated with appeals and cannot be deleted.', 13, 1);
        return 0;
    end

    if (select count(*) from dbo.REVENUEBENEFIT where BENEFITID = @ID) > 0
    begin
        raiserror('This benefit is associated with revenue and cannot be deleted.', 13, 1);
        return 0;                        
    end

    if (select count(*) from dbo.EVENTPRICEBENEFIT where BENEFITID = @ID) > 0
    begin
        raiserror('This benefit is associated with events and cannot be deleted.', 13, 1);
        return 0;                        
    end
    if (select count(*) from dbo.REGISTRANTBENEFIT where BENEFITID = @ID) > 0
    begin
        raiserror('This benefit is associated with events and cannot be deleted.', 13, 1);
        return 0;                        
    end
    if (select count(*) from dbo.MEMBERSHIPLEVELBENEFIT where BENEFITID = @ID) > 0
    begin
        raiserror('This benefit is associated with membership levels and cannot be deleted.', 13, 1);
        return 0;                        
    end

  if (select count(*) from dbo.BENEFITBENEFITOPTION where BENEFITID = @ID) > 0
    begin
        delete dbo.BENEFITBENEFITOPTION where BENEFITID = @ID
    end

    exec USP_BENEFIT_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
    return 0;
end