Hi everyone,
I am trying to create a report that takes a table of our customers that own equipment, then match it up to a Parts table that shows what type of parts they have purchased (Product Code). So the output displays the customer, all the machines they own and then in a grouped format the product code with total price
Example Product1 Product2 Product3
Customer A 0.00 50.00 75.00
Machine 1
Machine 2
Machine 3
So My problem is in my query (below) I keep getting dups of the machines and the total price is only giving me the last entry.
Query (I left out a group by as I want to understand where my mistakes are)
Example Data of parts table
Customer Prod_Line Qty Ext_Amnt
A B C CRUSHED BEAR 1 465
A B C CRUSHED BEAR 1 255.61
A B C CRUSHED BEAR 1 465
A B C CRUSHED BEAR 2 156
A B C CRUSHED BEAR 1 337.21
Example Data of Equip Table
ItemNumber Customer
POWERGRID 800 SN:7219836 A B C CRUSHED MATERIALS
Example of Data my query outputs
A B C CRUSHED POWERGRID 800 SN:7219836 BEAR 1.0
337.20999999999998
A B C CRUSHED POWERGRID 800 SN:7219836 BELT 1.0 1421.0
A B C CRUSHED POWERGRID 800 SN:7219836 CRBL 1.0
3.7994.530000000000001
A B C CRUSHED POWERGRID 800 SN:7219836 NUTS 1.0
46.399999999999999
A B C CRUSHED POWERGRID 800 SN:7219836 NUTS 1.0
39.880000000000003
A B C CRUSHED POWERGRID 800 SN:7219836 ROLL 2.0
559.25999999999999
A B C CRUSHED POWERGRID 800 SN:7219836 WPPG 1.0
989.76999999999998
A B C CRUSHED POWERGRID 800 SN:7219836 WPPG 1.0
2066.6700000000001
What am I not joining correctly?
I am trying to create a report that takes a table of our customers that own equipment, then match it up to a Parts table that shows what type of parts they have purchased (Product Code). So the output displays the customer, all the machines they own and then in a grouped format the product code with total price
Example Product1 Product2 Product3
Customer A 0.00 50.00 75.00
Machine 1
Machine 2
Machine 3
So My problem is in my query (below) I keep getting dups of the machines and the total price is only giving me the last entry.
Query (I left out a group by as I want to understand where my mistakes are)
Code:
SELECT Parts_GL_TableF.Customer, Equip_List_F.ItemDescription,
Parts_GL_TableF.Prod_Line, Parts_GL_TableF.Qty, Parts_GL_TableF.Ext_Amnt
FROM Parts_GL_TableF LEFT OUTER JOIN ED.dbo.Equip_List_F Equip_List_F ON
Parts_GL_TableF.Customer = Equip_List_F.Customer
WHERE ((Parts_GL_TableF.Inv_Date>='01/01/2009' And
Parts_GL_TableF.Inv_Date<=GetDate())) AND Parts_GL_TableF.Prod_Line IN
('ADPT', 'BEAR', 'BELT', 'BOLT', 'CHAN', 'CLTH', 'CPDS', 'CRBL', 'DRUM',
'EAGL', 'ELEP', 'ELPS', 'ENGP', 'ENPG', 'EXTE', 'FABR', 'FILT', 'FINL',
'GRID', 'HAZE', 'HOSE', 'HW', 'HYPG', 'HYPS', 'INER', 'KEY', 'MISC',
'NSHW', 'NSSC', 'NUTS', 'OBSO', 'OS', 'PINS', 'PULL', 'RADI', 'ROLL',
'SCRE', 'SEAL', 'SHAF', 'SHRP', 'SPRI', 'SPRO', 'STSC', 'STSH', 'TAPE',
'TESB', 'TRAC', 'TROM', 'TS', 'TSSC', 'USSC', 'VBEL', 'WASH', 'WHEL',
'WPPG', 'WPPR') AND Parts_GL_TableF.Customer NOT IN ('A C S')
ORDER BY Parts_GL_TableF.Customer, Equip_List_F.ItemDescription,
Parts_GL_TableF.Prod_Line
Example Data of parts table
Customer Prod_Line Qty Ext_Amnt
A B C CRUSHED BEAR 1 465
A B C CRUSHED BEAR 1 255.61
A B C CRUSHED BEAR 1 465
A B C CRUSHED BEAR 2 156
A B C CRUSHED BEAR 1 337.21
Example Data of Equip Table
ItemNumber Customer
POWERGRID 800 SN:7219836 A B C CRUSHED MATERIALS
Example of Data my query outputs
A B C CRUSHED POWERGRID 800 SN:7219836 BEAR 1.0
337.20999999999998
A B C CRUSHED POWERGRID 800 SN:7219836 BELT 1.0 1421.0
A B C CRUSHED POWERGRID 800 SN:7219836 CRBL 1.0
3.7994.530000000000001
A B C CRUSHED POWERGRID 800 SN:7219836 NUTS 1.0
46.399999999999999
A B C CRUSHED POWERGRID 800 SN:7219836 NUTS 1.0
39.880000000000003
A B C CRUSHED POWERGRID 800 SN:7219836 ROLL 2.0
559.25999999999999
A B C CRUSHED POWERGRID 800 SN:7219836 WPPG 1.0
989.76999999999998
A B C CRUSHED POWERGRID 800 SN:7219836 WPPG 1.0
2066.6700000000001
What am I not joining correctly?