on 2020 Aug 17 7:24 AM
Hi all,
I'm new to SQL and I managed to create a Sales Order vs AR Invoice query. However, when I try to include the Items Group Code into the query, it tells me that the multi-part identifier "T6.ItmsGrpCod' could not be bound. This is the code I used that works.
SELECT T0.[DocDate], T0.[DocNum] as 'Sales Order No.', T0.[CardName], T9.[SlpName] AS 'Sales Employee', T0.[U_Class], T1.[ItemCode], T1.[Dscription], T1.[Quantity] as 'SO Qty', T1.[OpenQty] as 'SO Open Qty', T0.DocStatus as 'SO Status', T0.[CANCELED] AS 'Canceled', T3.[Quantity] as 'Delivered Qty', T3.[OpenQty] as 'Delivered Open Qty', T4.[Quantity] as 'Invoice Qty'
FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry] left join DLN1 T2 on T2.baseentry=T1.docentry and T2.itemcode=T1.itemcode left join inv1 T3 on T3.baseentry=T2.docentry and T3.itemcode=T2.itemcode left join inv1 T4 on T4.baseentry=T1.docentry and T4.itemcode=T1.itemcode left outer join OSLP T9 on T9.SlpCode = T1.SlpCode
Request clarification before answering.
Hi,
The above query is OK, if only one line item in sales order, DO and AR invoice. If more than one line item, then we have to add line number to get correct result.
Try this,
SELECT T0.[DocDate], T0.[DocNum] as 'Sales Order No.', T0.[CardName], T9.[SlpName] AS 'Sales Employee', T0.[U_Class], T1.[ItemCode], T1.[Dscription], T1.[Quantity] as 'SO Qty', T1.[OpenQty] as 'SO Open Qty', T0.DocStatus as 'SO Status', T0.[CANCELED] AS 'Canceled', T3.[Quantity] as 'Delivered Qty', T3.[OpenQty] as 'Delivered Open Qty', T4.[Quantity] as 'Invoice Qty', T6.[ItmsGrpCod] as 'Item Group'
FROM
ORDR T0 INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OITM T5 ON T5.ItemCode = T1.ItemCode
left join DLN1 T2 on T2.baseentry=T1.docentry and T2.itemcode=T1.itemcode and T2.Baseline = T1.lineNum
left join inv1 T3 on T3.baseentry=T2.docentry and T3.itemcode=T2.itemcode and T3.Baseline = t2.LineNum
left join inv1 T4 on T4.baseentry=T1.docentry and T4.itemcode=T1.itemcode and T4.Baseline = t1.LineNum
left Join OITB T6 on T6.[ItmsGrpCod] = T5.[ItmsGrpCod] left outer join OSLP T9 on T9.SlpCode = T1.SlpCode
Regards,
Nagarajan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Check this below:
If does not return what is expected, then let us know and we can further check the expected result
SELECT T0.[DocDate], T0.[DocNum] as 'Sales Order No.', T0.[CardName], T9.[SlpName] AS 'Sales Employee',
T0.[U_Class],
T1.[ItemCode], T1.[Dscription], T1.[Quantity] as 'SO Qty', T1.[OpenQty] as 'SO Open Qty', T0.DocStatus as 'SO Status',
T0.[CANCELED] AS 'Canceled', T3.[Quantity] as 'Delivered Qty', T3.[OpenQty] as 'Delivered Open Qty',
T4.[Quantity] as 'Invoice Qty', T6.[ItmsGrpCod] as 'Item Group'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OITM T5 ON T5.ItemCode = T1.ItemCode
left join DLN1 T2 on T2.baseentry=T1.docentry and T2.itemcode=T1.itemcode
left join inv1 T3 on T3.baseentry=T2.docentry and T3.itemcode=T2.itemcode
left join inv1 T4 on T4.baseentry=T1.docentry and T4.itemcode=T1.itemcode
left Join OITB T6 on T6.[ItmsGrpCod] = T5.[ItmsGrpCod]
left outer join OSLP T9 on T9.SlpCode = T1.SlpCode
regards,
Jitin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Thank you for the help. However, when I attempted the query, I get duplicates of orders and also noticed that under T3 for 'Delivery Qty' and 'Delivered Open Qty' I get the same quantity. For example, on a sales order there is 100 cases of xyz, delivery is 100 cases, and the a/r invoice should be 100 as well. I noticed that Delivery in the select was still as T3 when AP was T3 as well. So I changed Delivery to T2 and I changed the query to include the BaseLine and LineNum like kothandaraman.nagarajan did:
SELECT T0.[DocDate], T0.[DocNum] as 'Sales Order No.', T0.[CardName], T9.[SlpName] AS 'Sales Employee', T0.[U_Class], T6.[ItmsGrpCod] as 'Item Group', T1.[ItemCode], T1.[Dscription], T1.[Quantity] as 'SO Qty', T1.[OpenQty] as 'SO Open Qty', T0.DocStatus as 'SO Status', T0.[CANCELED] AS 'Canceled', T2.[Quantity] as 'Delivered Qty', T2.[OpenQty] as 'Delivered Open Qty', T3.[Quantity] as 'Invoice Qty'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OITM T5 ON T5.ItemCode = T1.ItemCode
left join DLN1 T2 on T2.baseentry=T1.docentry and T2.itemcode=T1.itemcode and T2.Baseline = T1.LineNum
left join inv1 T3 on T3.baseentry=T2.docentry and T3.itemcode=T2.itemcode and T3.Baseline = T2.LineNum
left join inv1 T4 on T4.baseentry=T1.docentry and T4.itemcode=T1.itemcode and T4.Baseline = T3.LineNum
left Join OITB T6 on T6.[ItmsGrpCod] = T5.[ItmsGrpCod]
left outer join OSLP T9 on T9.SlpCode = T1.SlpCode
And the quantities are now accurate. However, for the sales orders that do not have a Delivery, it does not show an AR qty. Can this be fixed or would I have to do the query with only the Sales and the A/R?
Thanks.
User | Count |
---|---|
20 | |
10 | |
8 | |
7 | |
7 | |
6 | |
6 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.