DECLARE @CentralBookingType INT
SELECT @CentralBookingType = CONVERT(INT, ISNULL(KeyValue, 0)) FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'CentralBookingType'

IF ISNULL(@CentralBookingType, 0) > 0
BEGIN
  DECLARE @HotelNumber CHAR(1)
  DECLARE @HotelSetupNumber INT
  DECLARE @HotelCustomerNumber INT
  DECLARE @KeyValue VARCHAR(768)

  SELECT @HotelSetupNumber = HotelSetupNumber
  FROM HotelSetup WITH (NOLOCK) WHERE SearchKey = 'EInvoiceFilePath'  

  DECLARE dbcur CURSOR FOR
    SELECT SUBSTRING(SearchKey, LEN(SearchKey), 1), KeyValue
    FROM HotelSetup WITH (NOLOCK) WHERE SearchKey LIKE 'EInvoiceFilePath%'  
  OPEN dbcur

  FETCH NEXT FROM dbcur INTO @HotelNumber, @KeyValue

  WHILE @@FETCH_STATUS = 0
  BEGIN
    IF ISNUMERIC(@HotelNumber) = 1
    BEGIN
      SELECT @HotelCustomerNumber = CustomerNumber FROM Customer WITH (NOLOCK) WHERE HotelNumber = CONVERT(INT, @HotelNumber)
      IF ISNULL(@HotelSetupNumber, 0) > 0 AND @HotelCustomerNumber > 0
        EXEC UpdateHotelSetupChainSettings @HotelCustomerNumber, @HotelSetupNumber, @KeyValue
    END
    FETCH NEXT FROM dbcur INTO @HotelNumber, @KeyValue
  END 

  CLOSE dbcur
  DEALLOCATE dbcur

  DELETE HotelSetup WHERE SearchKey LIKE 'EInvoiceFilePath%' AND HotelSetupNumber <> @HotelSetupNumber  
END