K
KC_Cheer_Coach
My Inner Join is not working correctly. I have changed it so many times to
what should make sense, but my results now fluctuate from 18M records to 0
records!
This is what I have:
Table1: c.master, c.subacct, c.description, c.custid, c.custdiscount,
c.[master/sub discount]
Row 1 Data:
911111111, 911111112, TEST, 911111113, $200,000.00, NULL
Row 2 Data:
911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL, $200,000.00
Row 3 Data:
911111111, NULL, TOTAL FOR MASTER, NULL, NULL, $200,000.00
Table2: p.master, p.subacct, p.description, p.custid, p.custdiscount,
p.[master/sub discount]
Row 1 Data:
911111111, 911111112, TEST, 911111113, $195,230.47, NULL
Row 2 Data:
911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL, $195,230.47
Row 3 Data:
911111111, NULL, TOTAL FOR MASTER, NULL, NULL, $195,230.47
I created a UNION that encompasses a LEFT JOIN on table 1, LEFT JOIN on
table 2, and INNER JOIN. This UNION returns the following:
Field names: master, subacct, description, custid, p.custdiscount,
p.masterdiscount, c.custdiscount, c.masterdiscount, [custdiscount
difference], [master/sub level disct diff].
Row 1 Data: 911111111, 911111112, TEST, 911111113, $195,230.47, NULL,
$200,000.00, NULL, $4,769.53, NULL
Row 2 Data: 911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL,
$195,230.47, NULL, NULL, NULL, ($195,230.47)
Row 3 Data: 911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL, NULL, NULL,
$200,000.00, NULL, $200,000.00
Row 4 Data: 911111111, NULL, TOTAL FOR MASTER, NULL, NULL, $195,230.47,
NULL, NULL, NULL, ($195,230.47)
Row 5 Data: 911111111, NULL, TOTAL FOR MASTER, NULL, NULL, NULL, NULL,
$200,000.00, NULL, $200,000.00
Sorry, I wanted to make sure I gave you enough information this time~!
So, the qrys work in that all of my data is compared as in row 1, however
anywhere there is a "TOTAL FOR MASTER" or "TOTAL FOR SUBACCT" in the
description, it shows up on two lines when it should be on one line straight
across with the difference. There is also a "TOTAL FOR CYCLE" at the end of
each table where the master, subacct and custid are null, so I have to return
it based on those AND on masterdiscount is not null.
No matter what I try, I cannot get those "TOTAL FOR..." lines to compare
side by side like I can for the rest of the lines.
Can anyone help?
what should make sense, but my results now fluctuate from 18M records to 0
records!
This is what I have:
Table1: c.master, c.subacct, c.description, c.custid, c.custdiscount,
c.[master/sub discount]
Row 1 Data:
911111111, 911111112, TEST, 911111113, $200,000.00, NULL
Row 2 Data:
911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL, $200,000.00
Row 3 Data:
911111111, NULL, TOTAL FOR MASTER, NULL, NULL, $200,000.00
Table2: p.master, p.subacct, p.description, p.custid, p.custdiscount,
p.[master/sub discount]
Row 1 Data:
911111111, 911111112, TEST, 911111113, $195,230.47, NULL
Row 2 Data:
911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL, $195,230.47
Row 3 Data:
911111111, NULL, TOTAL FOR MASTER, NULL, NULL, $195,230.47
I created a UNION that encompasses a LEFT JOIN on table 1, LEFT JOIN on
table 2, and INNER JOIN. This UNION returns the following:
Field names: master, subacct, description, custid, p.custdiscount,
p.masterdiscount, c.custdiscount, c.masterdiscount, [custdiscount
difference], [master/sub level disct diff].
Row 1 Data: 911111111, 911111112, TEST, 911111113, $195,230.47, NULL,
$200,000.00, NULL, $4,769.53, NULL
Row 2 Data: 911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL,
$195,230.47, NULL, NULL, NULL, ($195,230.47)
Row 3 Data: 911111111, 911111112, TOTAL FOR SUBACCT, NULL, NULL, NULL, NULL,
$200,000.00, NULL, $200,000.00
Row 4 Data: 911111111, NULL, TOTAL FOR MASTER, NULL, NULL, $195,230.47,
NULL, NULL, NULL, ($195,230.47)
Row 5 Data: 911111111, NULL, TOTAL FOR MASTER, NULL, NULL, NULL, NULL,
$200,000.00, NULL, $200,000.00
Sorry, I wanted to make sure I gave you enough information this time~!
So, the qrys work in that all of my data is compared as in row 1, however
anywhere there is a "TOTAL FOR MASTER" or "TOTAL FOR SUBACCT" in the
description, it shows up on two lines when it should be on one line straight
across with the difference. There is also a "TOTAL FOR CYCLE" at the end of
each table where the master, subacct and custid are null, so I have to return
it based on those AND on masterdiscount is not null.
No matter what I try, I cannot get those "TOTAL FOR..." lines to compare
side by side like I can for the rest of the lines.
Can anyone help?