Hi there.
I am creating a new report in SQL and I need to know the qty on hand and the qty outstanding on a sales order.
I have the following query, however it is not giving me the correct results.
It seems like the grouping is not working the way I want it an it generates bad results for the above quantities.
SELECT [CRONUS USA, Inc_$Item].No_, SUM([CRONUS USA, Inc_$Item Ledger Entry].[Remaining Quantity]) AS EXPR1,
SUM([CRONUS USA, Inc_$Sales Line].[Outstanding Quantity]) AS EXPR2
FROM [CRONUS USA, Inc_$Item] INNER JOIN
[CRONUS USA, Inc_$Sales Line] ON [CRONUS USA, Inc_$Item].No_ = [CRONUS USA, Inc_$Sales Line].No_ LEFT OUTER JOIN
[CRONUS USA, Inc_$Item Ledger Entry] ON [CRONUS USA, Inc_$Item].No_ = [CRONUS USA, Inc_$Item Ledger Entry].[Item No_]
GROUP BY [CRONUS USA, Inc_$Item].No_
It seems like it is adding the sums up according to the number of Sales Lines and item Ledger entries that I have.
Can someone please help ??
Thanks.
0
Answers
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
It is producing the same results that I was getting before.
Here is an example.
Item No. 1000, qty on Hand = 32 (2 open Item ledger Entries) and qty on Sales order 104 (5 open Orders)
WHat I am getting with the above query or my query is this
Item no. 1000, qty on hand 160 (32*5 open sales orders), qty on Sales Order 108 (104 *2 open Ledger entries).
I hope this will make more sense to whoever is reading this.
My undestanding is that if you use the group by it should work the way I want it, but it is not.
Any other ideas ????
Thanks
Qty in ILE is
Qty in Sales Order
How do you want to see the results?
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Item No. Qty on ILE, QTY on Sales Order
1000 32.00 104.
1001 33 0.00
1002 0.00 37.00
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
I appreacite all of your info, however that query is not working form me.
Item No. Qty on ILE Qty on Sales Order
1000 160.00000000000000000000 208.00000000000000000000
1001 0.00000000000000000000 3.00000000000000000000
Here is the exact result I get when I run.
I only have 32 on hand, but I have 5 open sales orders, hence it is calculating my qty on ILE as 32 * 5.
The same with the qty on Sales order. I have 104, but I have 2 open ledger entries, hence it is calculating my qty on Sales Order as 104 * 2.
I copied and pasted your query to my sql reporting query area.
Thanks
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Thank you so much for your help.
Also to improve performance you should set a where clause for ILE only sum where Open = 1.
Also on qty on sales line you should set a where clause where "Document type" = 1 so that you only see orders.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n