SELECT LastPO.LastPONo AS PONo, LastPO.LastVersion, dbo.[CRONUS$Purchase Header Archive].[Currency Code],
dbo.[CRONUS$Purchase Header Archive].[Buy-from Vendor No_], dbo.[CRONUS$Purchase Header Archive].[Pay-to Vendor No_],
dbo.[CRONUS$Purchase Header Archive].[Pay-to Name], dbo.[CRONUS$Purchase Header Archive].[Order Date],
dbo.[CRONUS$Purchase Header Archive].[Document Date], dbo.[CRONUS$Purchase Header Archive].[Archived By],
dbo.[CRONUS$Purchase Header Archive].[No_ Printed], dbo.[CRONUS$Purchase Line Archive].No_,
dbo.[CRONUS$Purchase Line Archive].Description, dbo.[CRONUS$Purchase Line Archive].[Unit of Measure],
dbo.[CRONUS$Purchase Header Archive].[Receiving No_], dbo.[CRONUS$Purchase Line Archive].Quantity,
dbo.[CRONUS$Purchase Line Archive].[Direct Unit Cost], dbo.[CRONUS$Purchase Line Archive].[VAT _],
dbo.[CRONUS$Purchase Line Archive].Amount, dbo.[CRONUS$Purchase Line Archive].[Amount Including VAT]
FROM dbo.[CRONUS$Purchase Header Archive] INNER JOIN
(SELECT [Document Type], No_ AS LastPONo, MAX([Version No_]) AS LastVersion
FROM dbo.[CRONUS$Purchase Header Archive] AS [CRONUS$Purchase Header Archive_1]
GROUP BY [Document Type], No_
HAVING ([Document Type] = 1)) AS LastPO ON dbo.[CRONUS$Purchase Header Archive].No_ = LastPO.LastPONo AND
dbo.[CRONUS$Purchase Header Archive].[Version No_] = LastPO.LastVersion INNER JOIN
dbo.[CRONUS$Purchase Line Archive] ON
dbo.[CRONUS$Purchase Header Archive].[Document Type] = dbo.[CRONUS$Purchase Line Archive].[Document Type] AND
dbo.[CRONUS$Purchase Header Archive].No_ = dbo.[CRONUS$Purchase Line Archive].[Document No_] AND
dbo.[CRONUS$Purchase Header Archive].[Version No_] = dbo.[CRONUS$Purchase Line Archive].[Version No_]
WHERE (dbo.[CRONUS$Purchase Header Archive].[Order Date] >= CONVERT(DATETIME, '2016-10-01 00:00:00', 102)) AND
(dbo.[CRONUS$Purchase Header Archive].[Order Date] <= CONVERT(DATETIME, '2017-06-30 00:00:00', 102))
No comments:
Post a Comment