select m.empno, m.eff_dt, p.type_cd
from
main as m
LEFT OUTER JOIN
(
select empno,
eff_dt as start_dt,
coalesce (max(eff_dt) over (partition by empno order by eff_dt rows between 1 following and 1 following) - 1
, date '9999-12-31') as end_dt,
type_cd
from lkp
) as p
ON m.empno = p.empno
and m.eff_dt between p.start_dt and p.end_dt
order by 1,2
select m.empno, m.eff_dt, p.type_cd
from
main as m
LEFT OUTER JOIN
(
select empno,
eff_dt as start_dt,
coalesce (max(eff_dt) over (partition by empno order by eff_dt rows between 1 following and 1 following) - 1
, date '9999-12-31') as end_dt,
type_cd
from lkp
) as p
ON m.empno = p.empno
and m.eff_dt between p.start_dt and p.end_dt
order by 1,2