Two tables A (daily Loan Transaction table) and B (daily eod Loan Balance table).
Trying to write a select statement in DB2 AS400 to display daily loan transactions, eod Loan Balance and beginning loan balance (prior day) for selected date range.
Below query would give me daily loan transactions and eod loan balance. But need some help on modifying the query below to calculate beginning loan balance as well (balance as of 02/28/2015) for date range 03/01/2015 to 03/31/2015 selected.
select A.*, -- daily loan transactions
B.EOD_Loan_Balance
from A
inner join B
on A.date_id = B.date_id
and A.Loan_num = B.Loan_num
where a.date_id between 03/01/2015 to 03/31/2015
Note that previous day should be business day so if 02/28/2015 is not a business day then we need to pull eod balance of day before that and which should be a business day.
Any idea would be appreciated.
Thank you!
EOD_Loan_Balance where date_id = ('2015-03-01' - 1 day). Or are dates not contiguous? - Turophile