I need to create a list of Item Masters which will show the latest Invoice and Sales Order record. The code I have created shows ALL the records, I need the one with the newest DocDate....
Your assistance is greatly appreciated!
SELECT DISTINCT
T0.[ItemCode],
T1.[ObjType],
T1.[DocNum],
MAX(T1.[DocDate]) AS 'LastActivity'
FROM INV1 T0 INNER JOIN OINV T1 ON T0.[DocEntry] = T1.[DocEntry]
GROUP BY
T0.[ItemCode],
T1.[ObjType],
T1.[DocNum]
UNION ALL
SELECT DISTINCT
T0.[ItemCode],
T1.[ObjType],
T1.[DocNum],
MAX(T1.[DocDate]) AS 'LastActivity'
FROM RDR1 T0 INNER JOIN ORDR T1 ON T0.[DocEntry] = T1.[DocEntry]
GROUP BY
T0.[ItemCode],
T1.[ObjType],
T1.[DocNum]