DECLARE @Value BIT, @Hotel INT
SELECT @Value = KeyValue FROM HotelSetup WITH (NOLOCK) WHERE Searchkey = 'FiscalPrinterSweden'
SET @Value = ISNULL(@Value, 0)
IF @Value = 1 
BEGIN
  DECLARE @HotelSetupNumber INT
  SELECT @HotelSetupNumber = HotelSetupNumber FROM HOTELSETUP WITH (NOLOCK) WHERE SearchKey = 'FiscalPrinterSweden'
  DECLARE #Cursor CURSOR FAST_FORWARD READ_ONLY FOR
  SELECT CustomerNumber FROM Customer WITH (NOLOCK) WHERE (HotelNumber>0 OR LocalHotel=1) AND ISNULL(Customer.MarkAsDeleted, 0) = 0
  OPEN #Cursor
  FETCH NEXT FROM #Cursor INTO @Hotel
  WHILE @@FETCH_STATUS = 0 -- safe
  BEGIN
    IF ISNULL(
	  (SELECT COUNT(*) FROM HotelSetupValue HSV WITH (NOLOCK) 
	  INNER JOIN HotelSetupValueXTab HSVX WITH (NOLOCK) ON HSV.PK_ValueNumber = HSVX.FK_ValueNumber 
	  WHERE HSVX.CustomerNumber=@Hotel AND HSVX.HotelSetupNumber = @HotelSetupNumber), 0) = 0
	BEGIN
	  INSERT INTO HotelSetupValue (KeyValue) VALUES (@Value)
	  INSERT INTO HotelSetupValueXTab (HotelSetupNumber, CustomerNumber, Fk_ValueNumber) VALUES (@HotelSetupNumber, @Hotel, @@IDENTITY)
    END
    FETCH NEXT FROM #Cursor INTO @Hotel
  END
  CLOSE #Cursor
  DEALLOCATE  #Cursor
END
