CREATE PROCEDURE [dbo].[OnlineGetPackageDescriptionHall] @Dato DateTime, @ProductNumber int AS
SET NOCOUNT ON
/*
  Created by: SG inspired by KJ Oct 2016
  Description: Returns name and description of package on a product
*/


CREATE TABLE #PackageInfo
(
  View_DateStamp DATETIME,
  View_Id INT,
  View_FK_ProductNumber INT,
  View_PacketType INT
)

INSERT INTO #PackageInfo
  EXEC ProductPricePacketInfo @Dato, @Dato, @ProductNumber

SELECT Top 1 Packet.Text, Packet.Description
FROM #PackageInfo WITH (NOLOCK)
INNER JOIN ProductPricePacket WITH (NOLOCK) ON ProductPricePacket.Id = #PackageInfo.View_Id
INNER JOIN Packet WITH (NOLOCK) ON Packet.PacketNumber = ProductPricePacket.FK_PacketNumber
WHERE FK_ProductNumber = @ProductNumber
AND #PackageInfo.View_DateStamp = @Dato
AND ISNULL(ProductPricePacket.FK_PacketNumber, 0) > 0
AND PacketType = 0
ORDER BY Id DESC

DROP TABLE #PackageInfo
