IF (SELECT COUNT(*) FROM ProductHotelXTAB) = 0
BEGIN
	INSERT INTO ProductHotelXTAB (HotelCustomerNumber, ProductNumber)
	SELECT C.CustomerNumber,PP.ProductNumber FROM ProductPrice PP WITH (NOLOCK) 
	INNER JOIN RoomTypes RT WITH (NOLOCK) ON PP.RoomTypeNumber=RT.RoomTypeNumber
	INNER JOIN CUStomer C ON RT.HotelNumber = C.HotelNumber
	UNION
	SELECT DISTINCT C.CustomerNumber, PP.ProductNumber  FROM PacketItem_New PN WITH (NOLOCK)
	INNER JOIN PacketItem_newDepartmentxtab PNX WITH (NOLOCK) on PNX.PacketItemNumber = PN.PacketItemNumber AND Type = 1 
	INNER JOIN ProductPrice PP ON (PP.ArrivalPacketNumber = PN.PacketNumber) OR (PP.StayPacketNumber = PN.PacketNumber) OR (PP.DeparturePacketNumber = PN.PacketNumber)
	INNER JOIN Departments D WITH (NOLOCK) ON PNX.FK_Department = D.PK_Department
	INNER JOIN CUStomer C ON D.HotelNumber = C.HotelNumber
END


   