Hi,
I have got the following join:
SELECT l.cFirma AS Lieferant,
SUM(la.fEKNetto) AS Verbindlichkeiten,
l.kLieferant AS Lieferanten_ID,
100 - gk1.fFaktor * 100 AS Grundkondition,
MAX(gk1.dDatum) AS Datum
FROM tBestellung b, tArtikel a, tBestellpos p, tLieferant l, tLiefArtikel la, tGrundkondition gk1
WHERE
CAST('01.01.2010' AS DATETIME) <= CAST(b.dErstellt AS DATETIME)
AND b.cType = 'B'
AND p.tBestellung_kBestellung = b.kBestellung
AND a.kArtikel = p.tArtikel_kArtikel
AND l.kLieferant = la.tLieferant_KLieferant
AND a.kArtikel = la.tArtikel_kArtikel
AND gk1.tLieferant_kLieferant = l.kLieferant
GROUP BY l.kLieferant, cFirma, gk1.fFaktor
ORDER BY Verbindlichkeiten DESC, Lieferant
Please fokus on the table "tGrundkondition" alias gk1. There is a DATETIME column called "dDatum" and a foreign key "tLieferant_kLieferant".
Now I need only the latest data from this table, joined with the other stuff. I already used the MAX(gk1.dDatum) function, but I still get all entries of gk1. I need only the latest (with the highest dDate). Actually I don't need to output the date but only to filter the data.
I'm running this statement on Microsoft SQL Server via ODBC. Do you need any further information?
I hope you can help me. Thanks in advance.