IF NOT EXISTS (SELECT * FROM HotelSetup (NOLOCK) WHERE SearchKey = 'EnableRoomInRoom')
BEGIN
	DECLARE @HotelSetupKey INT
	DECLARE @HotelSetupValue VARCHAR(2000)
	DECLARE @HotelSetupValueKey INT	
	DECLARE @CustomerNumber INT


	INSERT INTO HotelSetup (SearchKey, LabelName, KeyValue, TextValue)
	SELECT 'EnableRoomInRoom', LabelName, KeyValue, TextValue FROM HotelSetup (NOLOCK) 
	WHERE SearchKey = 'EnableSubRooms'
	

	DECLARE #KeyCur CURSOR FOR
		SELECT HotelSetupNumber, KeyValue FROM HotelSetup (NOLOCK)
		WHERE SearchKey In ('EnableRoomInRoom', 'ResGroupRoomInRoom', 'CheckForAvailabilityOnRoomRelatedToSubRoom', 
		                    'IncludeOccupiedInOFS', 'SubRoomName','RoomName')
	
	Open #KeyCur

	FETCH NEXT FROM #KeyCur INTO @HotelSetupKey, @HotelSetupValue

	WHILE @@FETCH_STATUS = 0
	BEGIN
	

		DECLARE #ValueCur CURSOR FOR
			SELECT CustomerNumber FROM Customer (NOLOCK)
			WHERE ISNULL(HotelNUmber, -1) > -1
		OPEN #Valuecur
		FETCH NEXT FROM #Valuecur INTO @CustomerNumber

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

			SELECT @HotelSetupValueKey = @@IDENTITY

			INSERT INTO HotelSetupValueXTab (HotelSetupNumber, CustomerNumber, FK_ValueNumber)
			VALUES (@HotelSetupKey, @CustomerNumber, @HotelSetupValueKey)

			FETCH NEXT FROM #ValueCur INTO @CustomerNumber
		END
		
		CLOSE #Valuecur
		DEALLOCATE #Valuecur

		FETCH NEXT FROM #KeyCur INTO @HotelSetupKey, @HotelSetupValue
	END
	CLOSE #KeyCur
	DEALLOCATE #KeyCur
END