USP_EMAILCATEGORYPRIORITY_INCREASE_UPDATE
Executes the "Increase Email Category Priority" record operation.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | Input parameter indicating the ID of the record being updated. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the update. |
Definition
Copy
create procedure dbo.USP_EMAILCATEGORYPRIORITY_INCREASE_UPDATE
(
@ID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier
)
as
begin
set nocount on;
begin try
if @CHANGEAGENTID is null
exec dbo.[USP_CHANGEAGENT_GETORCREATECHANGEAGENT] @CHANGEAGENTID output;
declare @MINPRIORITY integer;
declare @CURRENTPRIORITY integer;
select @MINPRIORITY = min(PRIORITY) from dbo.[EMAILCATEGORYPRIORITY];
select @CURRENTPRIORITY = PRIORITY from dbo.[EMAILCATEGORYPRIORITY] where ID = @ID;
if (@CURRENTPRIORITY > @MINPRIORITY)
begin
-- swap priorities with item below
declare @NEXTPRIORITY integer = @CURRENTPRIORITY - 1;
begin
update dbo.[EMAILCATEGORYPRIORITY] set PRIORITY = @CURRENTPRIORITY, CHANGEDBYID = @CHANGEAGENTID where PRIORITY = @NEXTPRIORITY;
update dbo.[EMAILCATEGORYPRIORITY] set PRIORITY = @NEXTPRIORITY, CHANGEDBYID = @CHANGEAGENTID where ID = @ID;
end
end
end try
begin catch
exec dbo.[USP_RAISE_ERROR];
return 1;
end catch
end