Hi Peiter,
when you join two tables, both of them having start_date and end_date, then the join condition for those columns (in addition to currency_code, etc.) should be:
table1.start_date <= table2.end_date
and table2.start_date <= table1.end_date
With these conditions, you get the rows that have "intersecting" time periods.
And the new periods are:
case when table1.start_date <= table2.start_date then table2.start_date else table1.start_date end as NEW_START_DATE, /* greatest (...) */
case when table1.end_date <= table2.end_date then table1.end_date else table2.end_date end as NEW_END_DATE, /* least (...) */
Should be tested, of course.
Regards,
Vlad.
Hi Peiter,
when you join two tables, both of them having start_date and end_date, then the join condition for those columns (in addition to currency_code, etc.) should be:
table1.start_date <= table2.end_date
and table2.start_date <= table1.end_date
With these conditions, you get the rows that have "intersecting" time periods.
And the new periods are:
case when table1.start_date <= table2.start_date then table2.start_date else table1.start_date end as NEW_START_DATE, /* greatest (...) */
case when table1.end_date <= table2.end_date then table1.end_date else table2.end_date end as NEW_END_DATE, /* least (...) */
Should be tested, of course.
Regards,
Vlad.