15. Februar 2010 16:02
SELECT     CONVERT(money, [Cost per Unit]) AS Letzter_EK, [Item No_], MAX([Posting Date]) AS LetztesEkDat
FROM         [db$Value Entry]
WHERE     ([Item Ledger Entry Type] = 0) AND ([Document Type] = 6) AND ([Posting Date] BETWEEN CONVERT(DATETIME, '2008-01-01 00:00:00', 102) AND CONVERT(DATETIME, '2008-12-31 00:00:00', 102))
GROUP BY CONVERT(money, [Cost per Unit]), [Item No_]
HAVING      ([Item No_] = 'A169')
Letzter_EK   Item No_   LetztesEkDat
0,168   A169   2008-09-19 00:00:00.000
0,178   A169   2008-01-15 00:00:00.000
15. Februar 2010 16:57
SELECT TOP 1 CONVERT(money, [Cost per Unit]) AS Letzter_EK, [Item No_], [Posting Date] AS LetztesEkDat
FROM [dbo].[Häussling$Value Entry]
WHERE ([Item Ledger Entry Type] = 0) AND ([Document Type] = 6) 
  AND ([Posting Date] BETWEEN CONVERT(DATETIME, '2008-01-01 00:00:00', 102) AND CONVERT(DATETIME, '2008-12-31 00:00:00', 102))
  AND ([Item No_] = 'A169')
ORDER BY [Posting Date] DESC16. Februar 2010 07:59
16. Februar 2010 09:44
16. Februar 2010 10:05
SELECT     unterabfrage.*, CONVERT(money, [Cost per Unit]) AS Letzter_EK
FROM         
  (SELECT     [Item No_], MAX([Posting Date]) AS LetztesEkDat
  FROM         [db$Value Entry]
  WHERE     ([Item Ledger Entry Type] = 0) AND ([Document Type] = 6) AND ([Posting Date] BETWEEN CONVERT(DATETIME, '2008-  01-01 00:00:00', 102) AND CONVERT(DATETIME, '2008-12-31 00:00:00', 102))
  GROUP BY [Item No_]) as unterabfrage
INNER JOIN [db$Value Entry] on unterabfrage.[Item No_]= [db$Value Entry].[Item No_]
and unterabfrage.LetztesEkDat = [db$Value Entry].[Posting Date]
AND ([db$Value Entry].[Document Type] = 6)
AND ([db$Value Entry].[Item Ledger Entry Type] = 0)
;
16. Februar 2010 10:33