USP_PROSPECTCONSTITUENCY_DELETE

Executes the "Prospect 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_PROSPECTCONSTITUENCY_DELETE
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier
                    ) as
                        set nocount on;

                        declare @CURRENTDATE date;
                        set @CURRENTDATE = getdate();

                        if exists (
                                select
                                    1
                                from
                                    dbo.OPPORTUNITY O
                                    inner join dbo.PROSPECTPLAN PP on PP.ID=O.PROSPECTPLANID
                                    inner join dbo.PROSPECTDATERANGE PDR on PDR.CONSTITUENTID = PP.PROSPECTID
                                where
                                    PDR.ID = @ID and
                                    (PDR.DATEFROM <= @CURRENTDATE or PDR.DATEFROM is null) and
                                    (PDR.DATETO >= @CURRENTDATE or PDR.DATETO is null) and
                                    O.STATUSCODE = 2
                            )
                            raiserror('This constituent has a response-pending opportunity and therefore must remain a prospect.', 13, 1);

                        exec dbo.USP_PROSPECTDATERANGE_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;
                        return 0;