Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 8989

Trouble pulling invoice numbers into query

$
0
0

Hello,

I have been working on a query to pull in and link a Sales Order, it's Delivery Number, and the associated Invoice number. Most of the query works correctly with the exception of the Invoice Number. Currently only Open invoices are pulled into the report. We need all of the link invoices to be listed. I am not sure what is missing from the query. We have a "Ship Status" area that is used, if needed to list a time detail on the shipping status.

 

Here is the query so far:

 

SELECT DISTINCT

DATEDIFF(DD, T2.DocDueDate, T3.DocDueDate) AS 'Lapsed Days',

CASE
WHEN DATEDIFF(DD, T2.DocDueDate, T3.DocDueDate) >= 5 THEN 'Shipped'
WHEN DATEDIFF(DD, T2.DocDueDate, T3.DocDueDate) BETWEEN 1 AND 4 THEN 'Shipped'
WHEN DATEDIFF(DD, T2.DocDueDate, T3.DocDueDate) = 0 THEN 'Shipped'
WHEN DATEDIFF(DD, T2.DocDueDate, T3.DocDueDate) < 0 THEN 'Shipped'
ELSE 'Not Shipped'
END AS 'Ship Status',

T2.DocNum AS 'Sales Ord',
T2.DocDueDate AS 'Exp Del Date',
T3.DocNum AS 'Del Num',
T3.DocDueDate AS 'Del Date',
T5.DocNum AS 'Inv Num'

FROM RDR1 T0

LEFT OUTER JOIN DLN1 T1
ON T1.BaseType = 17
AND T0.DocEntry = T1.BaseEntry
AND T0.LineNum = T1.BaseLine
AND T0.ItemCode = T1.ItemCode

LEFT OUTER JOIN ORDR T2
ON T0.DocEntry = T2.DocEntry
AND T2.Canceled = 'N'

LEFT OUTER JOIN ODLN T3
ON T1.DocEntry = T3.DocEntry

LEFT JOIN INV1 T4 ON T0.LineNum = T4.BaseLine AND T0.DocEntry = T4.BaseEntry AND T4.BaseType=17

LEFT JOIN OINV T5 ON T4.DocEntry = T5.DocEntry

WHERE

T2.DocType = 'I'

ORDER BY

DATEDIFF(DD, T2.DocDueDate, T3.DocDueDate),
T2.DocDueDate DESC,
T2.DocNum,
T3.DocDueDate,
T3.DocNum,
T5.DocNum


FOR BROWSE

 

Any Help is Appreciated!


Viewing all articles
Browse latest Browse all 8989

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>