USP_SPONSORSHIPBATCH_DELETE

Executes the "Sponsorship Batch: 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_SPONSORSHIPBATCH_DELETE
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier
)
as begin
    --check deletion rules, if any 


    --remove the batch const group member first

    delete from dbo.BATCHSPONSORSHIPCONSTITUENTGROUPMEMBER
                     where GROUPID in 
                            (select BSC.ID from dbo.BATCHSPONSORSHIPCONSTITUENT BSC
                                 inner join dbo.BATCHSPONSORSHIP BS on BS.CONSTITUENTID = BSC.ID
                                 where BS.ID = @ID);

    --remove sponsorship constituent if the constituent was created in this batch

    delete from dbo.BATCHSPONSORSHIPCONSTITUENT
                     where ID in 
                            (select BSC.ID from dbo.BATCHSPONSORSHIPCONSTITUENT BSC
                                 inner join dbo.BATCHSPONSORSHIP BS on BS.CONSTITUENTID = BSC.ID
                                 where BS.ID = @ID);    

    delete from dbo.BATCHSPONSORSHIPCONSTITUENTACCOUNT
  where BATCHSPONSORSHIPCONSTITUENTACCOUNT.ID in
    (
      select CONSTITUENTACCOUNTID
      from dbo.BATCHSPONSORSHIP
      where BATCHSPONSORSHIP.ID = @ID
    );

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

    exec USP_BATCHSPONSORSHIP_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
    return 0;

end