I want to see the latest approval date (V.Datum) of a certain item (BauteilID) coming from a distinct supplier (m.Lieferanz_FreigabeID). If there is not any approval date in the table related to a supplier, it should return NULL. Instead I get the latest approval date of other suppliers of the same item.
I tried to include IsNULL
and IF
conditions but it did not work.
Select b.BauteilID, m.Lieferant_FreigabeID, Max(V.Datum) as Datum, m.Freigabe
From WPLabor.dbo.MapBauteilStahlwerk m
Join WPLabor.dbo.Bauteilspezifikation b on b.BauteilID = m.BauteilID
Join WPLabor.dbo.Verwendungsfreigabe v on v.BauteilID = b.BauteilID
LEFT Join WPLabor.dbo.Stahlwerkzeugnis s on v.StahlwerkID = s.StahlwerkID And m.Stahlwerk = s. Stahlwerk
group by b.BauteilID, m.Lieferant_FreigabeID, m.Freigabe
The result should be:
- ID1, Supplier1, Datum1, Freigabe1
- ID2, Supplier2, NULL, Freigabe2
Instead I get:
- ID1, Supplier1, Datum1, Freigabe1
- ID2, Supplier2, Datum1, Freigabe2
Help would by appreciated. Thanks in advance.