CREATE PROCEDURE DBO.GetPackageNumber @AProductNumber INT, @APacketType SMALLINT, @ADateTime DATETIME, @APacketNumber INT OUTPUT AS
SET NOCOUNT ON
/*
  Created by Kent Johansen Oktober 2013
  Return the packageNumber
  
  Changes:
    KJ 20140917: Bug: Fix for "Arrangementlines not created". Bug #172
  
*/
/*
SELECT TOP 1 @APacketNumber = FK_PacketNumber
FROM ProductPricePacket WITH (NOLOCK)
WHERE FK_ProductNumber = @AProductNumber
AND PacketType = @APacketType
AND StartDate >= @ADateTime
AND EndDate <= @ADateTime
ORDER BY Id Desc
*/
SET @APacketNumber = -1

SELECT TOP 1 @APacketNumber = FK_PacketNumber
FROM PacketInfoView WITH (NOLOCK)
INNER JOIN ProductPricePacket WITH (NOLOCK) ON ProductPricePacket.Id = View_Id
WHERE View_FK_ProductNumber = @AProductNumber
AND View_PacketType = @APacketType
AND View_DateStamp = @ADateTime
