USP_CONSTITUENTSOLICITCODE_DELETE

Executes the "Constituent Solicit Code: 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_CONSTITUENTSOLICITCODE_DELETE
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier
)
as begin

declare    @CONSENT tinyint = 255;

--if consent code remove any linked mail preferences

select    @CONSENT = SC.CONSENTCODE
from    dbo.CONSTITUENTSOLICITCODE csc
join    dbo.SOLICITCODE sc ON sc.ID = csc.SOLICITCODEID
where    csc.ID = @ID;

if @CONSENT > 0
BEGIN
    declare @contextCache varbinary(128);

    /* cache current context information */
    set @contextCache = CONTEXT_INFO();

    /* set CONTEXT_INFO to @CHANGEAGENTID */
    if not @CHANGEAGENTID is null
        set CONTEXT_INFO @CHANGEAGENTID

    delete  mp 
    from    dbo.MAILPREFERENCE mp
    join    dbo.CONSTITUENTSOLICITCODE csc on csc.id = mp.CONSTITUENTSOLICITCODEID
    where   csc.id = @ID;

    /* reset CONTEXT_INFO to previous value */
    if not @contextCache is null
        set CONTEXT_INFO @contextCache

END

    --check deletion rules, if any

    exec dbo.USP_CONSTITUENTSOLICITCODE_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
    return 0;
end