The scenario is as following,
All tables in the database has a Date column named EffectiveDate.
Data is imported into the database using a logic which detects and inserts changed records only.
Let us assume 5 imports happened between 1/1/2014 and 5/1/2014
So Table A has:
EffectiveDate id1 column1 column2 -------------- ---- -------- -------- 01/01/2014 1 ABC 123 02/01/2014 1 ABC 999 05/01/2014 1 XXX 999 01/01/2014 2 CCCC 555 03/01/2014 2 CCCC 444 04/01/2014 2 DDDD 444
and Table B has
EffectiveDate id2 column1 column2 -------------- ---- -------- -------- 01/01/2014 1 ZZZZ AAAAA 03/01/2014 1 ZZZZ AABBB 01/01/2014 2 TTTT AAAAA 05/01/2014 2 TTTT AABBB
Now The task is to create 3 set of views for all tables :
- The first set is to give the Effective data as of current date - The second set is to give latest data
- The third set is to give the data changes after today date (just next changes not the latest)
Consideration:
All views should return only one row for each id with applicable effective date.
If effective date is not available then the maximum effective date in the table less then the requested effective date should be used.
I was able to come up with solution for the Effective and Latest views but not for the third set of views (Next changes)
Any idea how to address this?