USP_DATAFORMTEMPLATE_EDIT_MKTFINDERNUMBER
The save procedure used by the edit dataform template "Finder Number Edit Form".
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the procedure. |
@FIXEDWIDTH | tinyint | IN | Fixed width |
@FINDERNUMBER | bigint | IN | Next finder number |
@CHECKDIGIT | bit | IN | Check digit |
Definition
Copy
CREATE procedure dbo.[USP_DATAFORMTEMPLATE_EDIT_MKTFINDERNUMBER]
(
@CHANGEAGENTID uniqueidentifier,
@FIXEDWIDTH tinyint,
@FINDERNUMBER bigint,
@CHECKDIGIT bit
)
as
set nocount on;
declare @OLDCHECKDIGIT bit;
declare @LAST_FINDERNUMBER bigint;
declare @CURRENTDATE datetime = getdate();
begin try
if @CHANGEAGENTID is null
exec dbo.[USP_CHANGEAGENT_GETORCREATECHANGEAGENT] @CHANGEAGENTID output;
select top(1)
@OLDCHECKDIGIT = [CHECKDIGIT],
@LAST_FINDERNUMBER = [LAST_FINDERNUMBER]
from dbo.[MKTFINDERNUMBER];
if @OLDCHECKDIGIT = 0 and @CHECKDIGIT = 1 and exists(select * from dbo.[MKTSEGMENTATIONFINDERNUMBER] inner join dbo.[MKTSEGMENTATION] on [MKTSEGMENTATION].[ID] = [MKTSEGMENTATIONFINDERNUMBER].[SEGMENTATIONID] where [MKTSEGMENTATION].[ACTIVE] = 0)
begin
raiserror('BBERR_MKTFINDERNUMBER_RANGESNOTACTIVATED', 13, 1);
raiserror('The check digit cannot be turned on because the system contains non-activated marketing efforts with reserved finder number ranges. To turn on the check digit, you must first perform one of the following actions: 1) remove the reserved finder number ranges from these non-activated marketing efforts, 2) activate these marketing efforts, or 3) delete these non-activated marketing efforts.', 1, 11);
end
update dbo.[MKTFINDERNUMBER] set
[MKTFINDERNUMBER].[FIXEDWIDTH] = @FIXEDWIDTH,
[MKTFINDERNUMBER].[FINDERNUMBER] = @FINDERNUMBER,
[MKTFINDERNUMBER].[LAST_FINDERNUMBER] = (case when @OLDCHECKDIGIT = 0 and @CHECKDIGIT = 1 then @FINDERNUMBER else @LAST_FINDERNUMBER end),
[MKTFINDERNUMBER].[CHECKDIGIT] = @CHECKDIGIT,
[MKTFINDERNUMBER].[CHANGEDBYID] = @CHANGEAGENTID,
[MKTFINDERNUMBER].[DATECHANGED] = @CURRENTDATE;
end try
begin catch
exec dbo.[USP_RAISE_ERROR];
return 1;
end catch
return 0;