SELECT T0.[docentry] As ‘Num’, T0.[CreateDate], T0.[DocDate], T0.[DocNum] as ‘No. DO’, T1.[BaseDocNum] as ‘No. SO’, T0.[CardCode] As ‘BP Code’, T0.[CardName], T0.[NumAtCard], T1.[WhsCode] as ‘WHSE’, T1.[ItemCode], T1.[Dscription], t0.comments, T1.[Quantity], T1.[Price], T1.OCRCODE AS ‘PLANT’, T3.docnum as [No. return], t2.quantity as [Qty Return], ISNULL(T1.[Quantity]-T2.[Quantity],T1.[Quantity]) AS [NET QTY]
FROM ODLN T0
left JOIN DLN1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN RDN1 T2 ON T0.DOCENTRY=T2.BASEENTRY
LEFT JOIN ORDN T3 ON T2.[DocEntry] = T3.[DocEntry]
WHERE T0.[DocDate] between [%0] and [%1] and left(t1.whscode,3) = [%2] and T0.[Canceled] = ‘N’