USP_FUNDRAISERCONSTITUENCY_DELETE

Executes the "Fundraiser Constituency: 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_FUNDRAISERCONSTITUENCY_DELETE
(
  @ID uniqueidentifier,
  @CHANGEAGENTID uniqueidentifier
)
as
  set nocount on;

  declare @CONSTITUENTID uniqueidentifier;

  select
    @CONSTITUENTID = CONSTITUENTID
  from
    dbo.FUNDRAISERDATERANGE
  where
    ID = @ID;

  --Only raise certain exceptions if we would be removing all of the fundraiser constituency rows for a given constituent.

  --We do not check dates anywhere else so only check if at least one of the constituencies remains.

  if not exists(select top 1 1 from dbo.FUNDRAISERDATERANGE where CONSTITUENTID = @CONSTITUENTID and ID <> @ID)
  begin

    if (select count(P.ID) from dbo.PROSPECT P where P.PROSPECTMANAGERFUNDRAISERID = @CONSTITUENTID) > 0
    begin
      raiserror ('ERR_PROSPECT_MANAGER', 13, 1);
      return 0;
    end

    if (select count(ID) from dbo.UFN_FUNDRAISER_PROSPECTPLANS(@CONSTITUENTID)) > 0
    begin
      raiserror ('ERR_PLAN', 13, 1);
      return 0;
    end

  end

  exec dbo.USP_FUNDRAISERDATERANGE_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;

  return 0;