CREATE PROCEDURE [dbo].[RegisterServiceRunning] @Value BIT, @ServiceId VARCHAR (30), @SearchKey VARCHAR (50) AS
/*
  Created by Nenad Blagojevic septembar 2015
  Register and Unregister a service running
  Comments:
  Changes:
  
*/
DECLARE @Run BIT, @Str VARCHAR(30), @IntValue INT
--Set ServiceRunning
SET @Str = ',[' + @ServiceId + ']'
IF @Value = 1
BEGIN
  SET @IntValue = 0
  SELECT @IntValue = CHARINDEX(@Str, KeyValue) FROM dbo.HotelSetup WITH (NOLOCK) WHERE UPPER(Searchkey) = UPPER(@SearchKey)
  IF @IntValue = 0
  BEGIN
    UPDATE dbo.HotelSetup SET KeyValue = KeyValue + @Str
    WHERE UPPER(Searchkey) = UPPER(@SearchKey)
    IF @@ROWCOUNT = 0
      INSERT INTO dbo.HotelSetup (Searchkey, KeyValue) VALUES (@SearchKey, @Str)
  END
END
ELSE
BEGIN
  UPDATE dbo.HotelSetup SET KeyValue = SUBSTRING(KeyValue, 1, CHARINDEX(@Str, KeyValue) - 1) + SUBSTRING(KeyValue, CHARINDEX(@Str, KeyValue) + LEN(@Str), LEN(KeyValue)) 
  WHERE UPPER(Searchkey) = UPPER(@SearchKey)  
END
