IF NOT EXISTS (SELECT * FROM ConferenceRooms (NOLOCK) 
			   where IsTable = 1)
BEGIN
	DECLARE @Date DATETIME
	DECLARE @HotelNumber INT
	DECLARE @ResourceType INT
	DECLARE @ID INT
	DECLARE @TableNumber INT
	DECLARE @ChairNumber INT


	SELECT @HotelNumber = HotelNumber FROM CUSTOMER (NOLOCK)
	WHERE LocalHotel = 1 AND MarkAsDeleted = 0 AND CustomerTypeNumber = 7

	SET @HotelNumber = ISNULL(@HotelNumber, 0)

	IF NOT EXISTS(select * from CONFERENCEROOMTYPES (nolock) where ResourceType = 2)
	BEGIN
	  EXEC dbo.GetNextNumber 'CONFERENCEROOMTYPESIDENTITY',	1, @ID OUTPUT
	  INSERT INTO CONFERENCEROOMTYPES (ConferenceRoomTypeNumber, Type, Text, HotelNumber, ResourceType, SortNumber)
	  VALUES (@ID, 'TAB', 'Table', @HotelNumber, 2, 2)	
	END

	SELECT @ResourceType = ConferenceRoomTypeNumber FROM CONFERENCEROOMTYPES (nolock)
	WHERE ResourceType = 2 AND HotelNumber = @HotelNumber

	SELECT @Date = SystemDate FROM SYSTEM

	DECLARE #RoomLineCur CURSOR LOCAL FAST_FORWARD FOR
	SELECT TableNumber, ChairNumber FROM RestaurantTableChairs (NOLOCK)
	WHERE MarkAsDeleted = 0

	OPEN #RoomLineCur

	FETCH NEXT FROM #RoomLineCur
	  INTO @TableNumber, @ChairNumber
	WHILE @@FETCH_STATUS = 0
	BEGIN	 
		EXEC dbo.GetNextNumber 'CONFERENCEROOMSIDENTITY',	1, @ID OUTPUT
		INSERT INTO ConferenceRooms (ConferenceRoomNumber, Number, ChairNumber, ConferenceRoomTypeNumber, TableDate, HotelNumber, Istable)
		VALUES (@ID, @TableNumber, @ChairNumber, @ResourceType, @Date, @HotelNumber, 1)
		
		INSERT INTO ConferenceRoomsXtab (ConferenceRoomNumber, CollectsConferenceRoomNumber)
		VALUES (@ID, @ID)
		
		FETCH NEXT FROM #RoomLineCur
	  INTO @TableNumber, @ChairNumber
	END
	CLOSE #RoomLineCur
	DEALLOCATE #RoomLineCur
END


