CREATE PROCEDURE dbo.ProductPricePacketInfoCSV @AFromDate DATETIME, @AEndDate DATETIME, @AProductNumberCSV VARCHAR(1000) AS
SET NOCOUNT ON

SELECT dtRange.IndividualDate AS View_DateStamp, MAX(Id) AS View_Id, FK_ProductNumber AS View_FK_ProductNumber, PacketType AS View_PacketType
FROM ProductPricePacket WITH (NOLOCK) 
CROSS APPLY dbo.DateRange(ProductPricePacket.StartDate, ProductPricePacket.EndDate, ProductPricePacket.FK_PacketNumber) AS dtRange
WHERE dtRange.IndividualDate BETWEEN @AFromDate AND @AEndDate
AND ProductPricePacket.FK_ProductNumber IN (SELECT Number FROM dbo.iter_intlist_to_table(@AProductNumberCSV))
GROUP BY dtRange.IndividualDate, FK_ProductNumber, PacketType