USP_BATCH_HASEXCLUSIVELOCK

Parameters

Parameter Parameter Type Mode Description
@BATCHID uniqueidentifier IN
@RESULT bit INOUT

Definition

Copy


create procedure dbo.USP_BATCH_HASEXCLUSIVELOCK
(
    @BATCHID uniqueidentifier,
    @RESULT bit = 0 output
)
as
begin
    declare @LOCKNAME nvarchar(36) = upper(cast(@BATCHID as nvarchar(36)));

    -- Function returns 0 if a lock cannot be granted, implying that there is one already in place

    if (select APPLOCK_TEST('public',@LOCKNAME,'Exclusive','Session')) = 0
        set @RESULT = 1;
end