USP_CAMPAIGN_DELETE
Executes the "Campaign: 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_CAMPAIGN_DELETE (
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier
) as begin
set nocount on;
declare @HIERARCHYPATH hierarchyid;
select @HIERARCHYPATH = CAMPAIGN.HIERARCHYPATH from dbo.CAMPAIGN where CAMPAIGN.ID = @ID;
if exists (
select
NAMINGOPPORTUNITY.ID
from
dbo.NAMINGOPPORTUNITY
where
NAMINGOPPORTUNITY.CAMPAIGNID = @ID
)
raiserror('ERR_CAMPAIGNDELETE_CAMPAIGNHASNAMINGOPPORTUNITY', 13, 1);
if exists (
select
CAMPAIGN.ID
from
dbo.CAMPAIGN
where
CAMPAIGN.HIERARCHYPATH.GetAncestor(1) = @HIERARCHYPATH
)
raiserror('ERR_CAMPAIGNDELETE_CAMPAIGNHASCHILDREN',13,1);
-- Clear subpriorities associated with the campaign's priorities. These can't be cleared
-- through a cascade delete since adding it to the FK could cause cycles. The CAMPAIGNPRIORITY
-- records will be cleared through cascade delete.
declare @contextCache varbinary(128);
--cache current context information
set @contextCache = CONTEXT_INFO();
--set CONTEXT_INFO to @CHANGEAGENTID
set CONTEXT_INFO @CHANGEAGENTID;
delete from dbo.CAMPAIGNSUBPRIORITY
where CAMPAIGNPRIORITYID in (select ID from dbo.CAMPAIGNPRIORITY where CAMPAIGNID = @ID)
--reset CONTEXT_INFO to previous value
if not @contextCache is null
set CONTEXT_INFO @contextCache;
exec dbo.USP_CAMPAIGN_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;
end