I am replacing a "Bundle" of queries, make tables etc with what may well be one sql.
Here is my basic Union sql
This "Works" except that I have hard coded "01/01/2010" where it should be the actual date from another table. Require ADPK from TBLLOAN.LDPK and BanklID & StatementDate from tblBankStatements.
Here is the sql that gathers this info.
And here is the other side of the Union Query with all data
Can I combine the two sqls into the union query to give me all the records with the info I need? or
Do I need to do 3 sql's two to collect the relevant data and the 3rd, the union query?
or should I use some temp tables and macros
Here is my basic Union sql
Code:
SELECT T.LDPK, T.TRNACTDTE, T.TRNTYP, T.TRNDR, T.TRNPR, 0 AS PaymentAmt
FROM TBLTRANS AS T
UNION ALL SELECT P.LoanID AS LDPK, "01/01/2010" AS TRNACTDTE, P.PayMethod AS TRNTYP, 0 AS TRNDR, 0 AS TRNPR, P.PaymentAmt
FROM tblMemberRepayments AS P;
This "Works" except that I have hard coded "01/01/2010" where it should be the actual date from another table. Require ADPK from TBLLOAN.LDPK and BanklID & StatementDate from tblBankStatements.
Here is the sql that gathers this info.
Code:
SELECT TBLLOAN.ADPK, tblBankStatements.StatementDate, tblBankStatements.BankID, tblMemberRepayments.LoanID, tblMemberRepayments.PayMethod, tblMemberRepayments.PaymentAmt
FROM TBLLOAN INNER JOIN (tblBankStatements INNER JOIN tblMemberRepayments ON tblBankStatements.StatementID = tblMemberRepayments.StatementID) ON TBLLOAN.LDPK = tblMemberRepayments.LoanID;
And here is the other side of the Union Query with all data
Code:
SELECT TBLTRANS.TRNACTDTE, TBLTRANS.LDPK, TBLLOAN.ADPK, TBLTRANS.TRNTYP, TBLTRANS.TRNDR, TBLTRANS.TRNPR
FROM TBLLOAN INNER JOIN TBLTRANS ON TBLLOAN.LDPK = TBLTRANS.LDPK;
Can I combine the two sqls into the union query to give me all the records with the info I need? or
Do I need to do 3 sql's two to collect the relevant data and the 3rd, the union query?
or should I use some temp tables and macros
