USP_DESIGNATIONLEVEL_DELETE

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


                        declare @NUMDESIGNATIONS int;

                        declare @SYSTEMGENERATEDDESIGNATIONID uniqueidentifier;
                        select @SYSTEMGENERATEDDESIGNATIONID = DESIGNATION.ID
                        from dbo.DESIGNATION
                        where DESIGNATION.DESIGNATIONLEVEL1ID = @ID
                            and DESIGNATION.SYSTEMGENERATED = 1;

                        select @NUMDESIGNATIONS = count(*
                        from dbo.DESIGNATION
                        where DESIGNATION.DESIGNATIONLEVEL1ID = @ID or
                            DESIGNATION.DESIGNATIONLEVEL2ID = @ID or
                            DESIGNATION.DESIGNATIONLEVEL3ID = @ID or
                            DESIGNATION.DESIGNATIONLEVEL4ID = @ID or
                            DESIGNATION.DESIGNATIONLEVEL5ID = @ID;

                        if @NUMDESIGNATIONS > 0
                        begin
                            if @SYSTEMGENERATEDDESIGNATIONID is not null and @NUMDESIGNATIONS = 1
                                exec dbo.USP_DESIGNATION_DELETE @SYSTEMGENERATEDDESIGNATIONID, @CHANGEAGENTID;
                            else
                            begin
                                raiserror('This record has associated designations and cannot be deleted.', 13, 1);
                                return 0;
                            end
                        end

                        exec USP_DESIGNATIONLEVEL_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
                        return 0;
                    end