Below is a query linking Purchase Orders to Sales Orders. My understanding is that in order to include delivery doc # to this report, I need to add one more table - ODLN (so there would be an additional field titled "Delivery Doc#" aka [ODLN.DocNum]). My problem is I'm not sure how to join ODLN in the below query without messing anything up.
ODLN.DocNum pretty much verifies that the PO did get placed at the time of the SO submission.
SELECT DISTINCT
o.CardName AS 'Customer Name'
,(isnull(c1.Street,'') + ', ' + isnull(c1.Block,'') + ', ' + isnull(c1.City,'') + ', ' + isnull(c1.[State],'') + ' ' + isnull(c1.ZipCode,'')) AS 'Customer Address'
,cpr.[Name] AS 'Customer Contact'
,cpr.Tel1 AS 'Customer Phone'
,cpr.E_MailL AS 'Customer Email'
,o.DocNum AS 'Sales Order #'
,p.DocNum AS 'PO # to Barracuda'
,l.ItemCode AS 'SKU'
,l.Dscription AS 'Desc'
,l.Quantity AS 'Qty'
,l.Price
,s.SlpName AS 'Sales Rep'
FROM
ORDR o
INNER JOIN RDR1 l ON o.DocEntry = l.DocEntry
LEFT JOIN POR1 p1 ON l.DocEntry = p1.BaseEntry AND l.LineNum = p1.BaseLine
LEFT JOIN OPOR p ON p1.DocEntry = p.DocEntry
INNER JOIN OCRD c ON o.CardCode = c.CardCode
INNER JOIN CRD1 c1 ON c.CardCode = c1.CardCode AND c.BillToDef = c1.[Address]
LEFT JOIN OCPR cpr ON c.CntctPrsn = cpr.[Name] AND c.CardCode = cpr.CardCode
INNER JOIN OITM itm ON l.ItemCode = itm.ItemCode
INNER JOIN OITB i ON itm.ItmsGrpCod = i.itmsGrpCod
INNER JOIN OSLP s ON o.SlpCode = s.SlpCode
WHERE
o.Canceled = 'N'
AND c1.AdresType = 'B'
AND i.ItmsGrpCod = 109
AND o.DocDate BETWEEN '6/01/2014 00:00:00.000' AND '9/30/2014 00:00:00.000'
ORDER BY
o.DocNum