The purpose is to calculate the Total-IN and the Total-OUT of the UNION tables A and B where the summed records correspond to a certain ID = 100.
The UNION query below only gives the totals of the matching records from table A (= 1st part of the query up to UNION) - and does not add any matching record from table B (= 2nd part of the query after UNION).
How can I make this code work correctly?
Thanks.
The UNION query below only gives the totals of the matching records from table A (= 1st part of the query up to UNION) - and does not add any matching record from table B (= 2nd part of the query after UNION).
How can I make this code work correctly?
Thanks.
Code:
SQL="SELECT "&_
"(Select Sum(Out) from Table_A where ID=100) AS TotOUT, "&_
"(Select sum(In) from Table_A where ID=100) AS TotIN "&_
"FROM Table_A "&_
"WHERE (ID=100) "&_
"UNION ALL SELECT "&_
"(Select Sum(Out) from Table_B where ID=100) AS TotOUT, "&_
"(Select sum(In) from Table_B where ID=100) AS TotIN "&_
"FROM Table_B "&_
"WHERE (ID=100)"