IF NOT EXISTS(SELECT * FROM HotelSetup (NOLOCK) WHERE SearchKey ='NameListExtraFields')
BEGIN 
	DECLARE @KeyValue VARCHAR(255)
	DECLARE @InterfaceCall VARCHAR(10)
	DECLARE @OrderID VARCHAR(10)

	SET @KeyValue = ';'

	SELECT @InterfaceCall = KeyValue FROM HotelSetup (NOLOCK)
	WHERE SearchKey = 'ShowInterfaceCallOnNameGridExtra'

	IF ISNULL(@InterfaceCall, 0) = 1
		SET @KeyValue = @KeyValue + '0,'

	SELECT @OrderID = KeyValue FROM HotelSetup (NOLOCK)
	WHERE SearchKey = 'OrderIDInNameList'

	IF ISNULL(@OrderID, 0) = 0
		SET @KeyValue = @KeyValue + '1'
	ELSE
		SET @KeyValue = @KeyValue + '2'

	SET @KeyValue = @KeyValue + ',3'

	DECLARE @SetupID INT

	INSERT INTO HotelSetup (SearchKey)
	VALUES ('NameListExtraFields')
	SELECT @SetupID = @@IDENTITY

	DECLARE @HotelCustomerNumber INT
	DECLARE @ValueID INT

	DECLARE db_cur CURSOR LOCAL READ_ONLY FAST_FORWARD FOR
		SELECT CustomerNumber
		FROM Customer (NOLOCK)
		WHERE CustomerTypeNumber = 7 AND MARKASDELETED = 0

	OPEN db_cur
	FETCH NEXT FROM db_cur INTO @HotelCustomerNumber

	WHILE @@FETCH_STATUS = 0
	BEGIN
		INSERT INTO HotelSetupValue (KeyValue)
		VALUES (@KeyValue)
		SELECT @ValueID = @@IDENTITY

		INSERT INTO HotelSetupValueXTab (HotelSetupNumber, CustomerNumber, FK_ValueNumber)
		VALUES (@SetupID, @HotelCustomerNumber, @ValueID)

		FETCH NEXT FROM db_cur INTO @HotelCustomerNumber
	END

	CLOSE db_cur
	DEALLOCATE db_cur

	DECLARE @HotelSetupNumber INT

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

	IF ISNULL(@HotelSetUpNumber, 0) > 0
	BEGIN
		DELETE FROM HotelSetupLog WHERE HotelSetUpNumber = @HotelSetupNumber
		DELETE FROM HotelSetup WHERE HotelSetUpNumber = @HotelSetupNumber
	END

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

	IF ISNULL(@HotelSetUpNumber, 0) > 0
	BEGIN
		DELETE FROM HotelSetupLog WHERE HotelSetUpNumber = @HotelSetupNumber
		DELETE FROM HotelSetup WHERE HotelSetUpNumber = @HotelSetupNumber
	END
END