By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select 'A12' as personid, 'abc' as companyid, convert(date, '2020-05-01') as start_dt, '2020-05-03' as end_dt
into t
union all
select 'B23' as personid, 'def' as companyid, convert(date, '2020-06-08') as start_dt, '2020-06-14' as end_dt
2 rows affected
with cte as (
select PersonID, CompanyID, Start_DT as new_dt, End_DT
from t
union all
select PersonID, CompanyID, dateadd(day, 1, new_dt), End_DT
from cte
where new_dt < end_dt
)
select PersonID, CompanyID, new_dt
from cte;
PersonID | CompanyID | new_dt |
---|---|---|
A12 | abc | 2020-05-01 |
B23 | def | 2020-06-08 |
B23 | def | 2020-06-09 |
B23 | def | 2020-06-10 |
B23 | def | 2020-06-11 |
B23 | def | 2020-06-12 |
B23 | def | 2020-06-13 |
B23 | def | 2020-06-14 |
A12 | abc | 2020-05-02 |
A12 | abc | 2020-05-03 |