
CREATE PROCEDURE [dbo].[bl_SyncStart]
	@Type nvarchar(50)
	as
BEGIN
--select * from dbo.blSync
--update dbo.blSync set Status=2 where Id = 1
update dbo.blSync set Status=-1 where Type = @Type and Status = 1 and DATEDIFF(second,[Start], CURRENT_TIMESTAMP)>180;

IF EXISTS (select * from dbo.blSync where Status=1 and Type = @Type)
BEGIN
select -1;
END
ELSE
BEGIN
INSERT INTO [dbo].[blSync]
           ([Type]
           ,[Status]
           ,[Start]
           ,[Stop])
     VALUES
           (@Type,1,CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
		   SELECT SCOPE_IDENTITY();
END
 

END

