2017-03-07 80 views
2

以下是將採購訂單鏈接到銷售訂單的查詢。我的理解是,爲了將交付文檔編號包括到此報告中,我需要再添加一個表格 - ODLN(因此將會有一個名爲「Delivery Doc#」又名[ODLN.DocNum]的字段)。我的問題是我不知道如何在下面的查詢中加入ODLN而不會搞亂任何東西。添加交付信息以在SAP Crystal Reports中查詢

ODLN.DocNum很大程度上驗證了PO在SO提交時的位置。

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 
+0

該ODLN.DocNum與現有的表/列有什麼關係? –

+0

交付單據驗證是否在提交SO時獲得了PO。 – vnguyen

+0

該表與其他人有什麼關係,因此我們可以計算出加入? –

回答

0

從評論,很明顯,你不知道用什麼字段來加入ODLN到你當前的查詢。

我會跟着錢。

如果我記得沒錯,ODLN.TransId加入到OJDT.TransId中,並且OJDT.BaseRef加入到OPOR.DocNum中。

從你的問題中不清楚的是,如果你只希望那些有交付單的PO,只有那些沒有,或者所有PO(有或沒有,有交付單的人)。一旦我們知道了,我們可以告訴你是使用左邊還是內部,如何處理Null等。但坦率地說,就SAP而言,這部分是微不足道的。