Hi,
Happy New Year!
With this code, I want a total per each company of what was (shipped * price) for last month. For Example:
101 Acme Inc. $2500
102 Acme Co. $760
The QTY * Price are inconsistantly incorrect. Sometimes they are correct - some times wrong.
For a TEST I printed out the data. The last column has the correct math(product).
I see that the product is wrong, but how to fix it??
TIA
Happy New Year!
With this code, I want a total per each company of what was (shipped * price) for last month. For Example:
101 Acme Inc. $2500
102 Acme Co. $760
The QTY * Price are inconsistantly incorrect. Sometimes they are correct - some times wrong.
Code:
SELECT C.ID, C.NAME, SUM(SH.QTY * OL.PRICE) AS [TOTAL DOLLARS]
FROM CUSTOMER C
INNER JOIN USERS U ON C.ID = U.ID
INNER JOIN ORDERS O ON C.ID = O.ID
INNER JOIN ORDER_LINE OL ON O.ID = OL.ORDER_ID
INNER JOIN SHIP_LINE SL ON OL.ORDER_ID = SL.ORDER_ID
INNER JOIN SHIPPER SH ON SL.PACKAGE_ID = SH.PACKAGE_ID
WHERE U.P_ID = 'CCNNTT' AND
U.D_ID = 'U-0022' AND
((SH.SHIPPED_DATE >= DATEADD(MM,DATEDIFF(MM,0,GETDATE())-1,0)) AND
(SH.SHIPPED_DATE < DATEADD(MM,DATEDIFF(MM,0,GETDATE()),0)))
GROUP BY C.ID, C.NAME;
HTML Code:
ID Company qty Price date output should be:
101 Acme Inc 8 8.99 12/11/2012 71.92 71.92
101 Acme Inc 8 20.54 12/11/2012 164.32 164.32
101 Acme Inc 8 25 12/12/2012 200 200
101 Acme Inc 40 8.99 12/11/2012 359.6 359.6
101 Acme Inc 40 20.54 12/11/2012 821.6 821.6
101 Acme Inc 300 0.9 12/19/2012 1080 270
101 Acme Inc 2500 0.79 12/18/2012 1975 1975
102 Acme Co. 1 38.22 12/16/2012 76.44 38.22
102 Acme Co. 1 40.93 12/16/2012 81.86 40.93
102 Acme Co. 1 42.1 12/15/2012 84.2 42.1
102 Acme Co. 1 51.64 12/15/2012 103.28 51.64
102 Acme Co. 1 52.3 12/20/2012 52.3 52.3
102 Acme Co. 1 53.4 12/15/2012 106.8 53.4
TIA