Skip to Content
0
Jun 29, 2020 at 01:23 AM

Last purchase reference # for an invoice line

107 Views

Hey all,

I have a query that displays parts used for a service call. I need the reference number in this query to show the most recent reference number for that product purchase. At the moment its showing me an older number. My query is below, all help will be appreciated as always.

SELECT T1."callID",T3."ItemCode", T3."Dscription", T3.Quantity,T5.NumAtCard,T3.DocEntry
FROM OSCL T1
LEFT JOIN SCL4 T2 ON T1."callID" = T2."SrcvCallID"
INNER JOIN INV1 T3 ON T2."Object" = T3."ObjType" AND T2."DocAbs" = T3."DocEntry" AND T2."Object" = '13'
INNER JOIN PCH1 T4 ON T4.ItemCode = T3.ItemCode
INNER JOIN OPCH T5 ON T5.[DocEntry] = T4.[DocEntry]
WHERE T5.CardName LIKE '%%Alliance%%'