add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select *
into parent
from (values (1, 2016, 2020, 2.0),
(2, 2018, 2021, 3.5)
) v(ID, StartYear, EndYear, Capacity)
2 rows affected
with cte as ( -- may require "recursive" keyword
select id, startyear as year, capacity, endyear
from parent
union all
select id, year + 1, capacity, endyear
from cte
where year < endyear
)
select id, year, capacity
from cte
order by id, year;
id year capacity
1 2016 2.0
1 2017 2.0
1 2018 2.0
1 2019 2.0
1 2020 2.0
2 2018 3.5
2 2019 3.5
2 2020 3.5
2 2021 3.5