Hi Ravi,
T0.docentry = t2.docentry is not right. If your AP invoice is directly linked to PO, try this:
SELECT Distinct T0.[DocNum], T0.[CardCode], T0.[CardName], T1.[ItemCode], T1.[Dscription], T1.[Quantity], T1.[ShipDate], T1.[ActDelDate], t3.docdate 'PO date'
FROM [dbo].[OPCH] T0 INNER JOIN PCH1 T1 ON T0.DocEntry = T1.DocEntry
LEFT join por1 t2 on t0.docentry = t2.trgetentry and t1.baseline=t2.linenum
left join opor t3 on t3.DocEntry=T2.DocEntry
WHERE T0.[DocDate] between [%0] and [%1]
If it is working, add back your UDF.
Thanks,
Gordon