Given this setup :
=> tableA => with 2 fields A_NR and A_Nm - the records are (for field A_NR) e.g. numbers as 550 and 560 and 570 and 580 ... / field A_Nn = name
=> tableBB and tableCC with records whose fields BB_NR and CC_NR may contain the same numbers as in tableA
(other fields of this tables are date, amountP, amountM, ... )
to make
a list of all the fields A_NR/A_Nm with the total amountM and/or the total amountP (=TrDTV or TrCTW) of all the corresponding records from tableBB and tableCC (UNION ALL) with the same A_NR
and at the bottom the sum of all the amounts (=TTrDTV or TTrCTW)
I tried to make a SELECT query for this UNION ALL and JOIN combination, but it does not work.
Database = Access
Thanks for tips and help.
=> tableA => with 2 fields A_NR and A_Nm - the records are (for field A_NR) e.g. numbers as 550 and 560 and 570 and 580 ... / field A_Nn = name
=> tableBB and tableCC with records whose fields BB_NR and CC_NR may contain the same numbers as in tableA
(other fields of this tables are date, amountP, amountM, ... )
to make
a list of all the fields A_NR/A_Nm with the total amountM and/or the total amountP (=TrDTV or TrCTW) of all the corresponding records from tableBB and tableCC (UNION ALL) with the same A_NR
and at the bottom the sum of all the amounts (=TTrDTV or TTrCTW)
I tried to make a SELECT query for this UNION ALL and JOIN combination, but it does not work.
Database = Access
Thanks for tips and help.
Code:
sqlJ = "SELECT BB_NR,date,number,name,amountM,amountP,DT_V,CT_W, tableA.A_NR, tableA.A_Nm,"&_
"(Select Sum([DT_V]) FROM tableBB) AS TTrDTV,"&_
"(Select Sum([CT_W]) FROM tableBB) AS TTrCTW,"&_
"(Select Sum([DT_V]) FROM tableBB WHERE [tableBB].BB_NR=[tabelA].A_NR) AS [TrDTV],"&_
"(Select Sum([CT_W]) FROM tableBB WHERE [tableBB].BB_NR=[tableA].A_NR) AS [TrCTW]"&_
"FROM tableA left JOIN tableBB ON tableA.A_NR=tableBB.BB_NR WHERE tableA.A_Nr is not null "&_
"UNION ALL "&_
"SELECT tableCC.JAccNR,tableCC.date,tableCC.number,tableCC.name,tableCC.amountM,tableCC.amountP,tableCC.DT_V,tableCC.CT_W, tableA.A_NR, tabelA.A_Nm "&_
"FROM tableA left JOIN tableCC ON tableA.A_NR=tableCC.CC_NR WHERE tableA.A_NR is not null "&_
"ORDER BY tableA.A_NR ASC"