CREATE PROCEDURE [dbo].[InsertProductHotelsFromRoomType] @RoomTypeNumber INT, @HotelCustomerNumber INT
AS
BEGIN
	DECLARE @ProductNumber INT
	DECLARE #cur CURSOR FOR
		SELECT DISTINCT pp.ProductNumber FROM ProductPrice pp WITH (NOLOCK)
		INNER JOIN Products p WITH (NOLOCK) ON pp.ProductNumber = p.ProductNumber and ISNULL(p.MarkAsDeleted, 0) = 0
		WHERE pp.RoomtypeNumber = @RoomTypeNumber

	OPEN #cur

	FETCH NEXT FROM #Cur INTO @ProductNumber
	WHILE @@FETCH_STATUS = 0
	BEGIN
		FETCH NEXT FROM #Cur INTO @ProductNumber
		IF NOT EXISTS (SELECT * FROM ProductHotelXTAB WITH (NOLOCK) WHERE ProductNumber = @ProductNumber AND HotelCustomerNumber = @HotelCustomerNumber)
			INSERT INTO ProductHotelXTAB (ProductNumber, HotelCustomerNumber)
			VALUES (@ProductNumber, @HotelCustomerNumber)
	END

	CLOSE #cur
	DEALLOCATE #cur
END
GO
