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.
CREATE TABLE Parent (ID INTEGER, StartYear INTEGER, EndYear INTEGER, Capacity FLOAT);
INSERT INTO Parent (ID, StartYear, EndYear, Capacity) VALUES
('1', '2016', '2020', '2.0'),
('2', '2018', '2021', '3.5');
2 rows affected
CREATE TABLE Child (ID INTEGER, Year INTEGER, Capacity FLOAT);
declare @maxendyear int = (select max(endyear) from parent);
with years AS (
select min(startyear) year from parent
union all
select year + 1 FROM years where year + 1 <= @maxendyear
)
insert into child (id, year, capacity)
select
p.id, y.year, p.capacity
from parent p inner join years y
on y.year between p.startyear and p.endyear

9 rows affected
select * from child
order by id, year
ID Year Capacity
1 2016 2
1 2017 2
1 2018 2
1 2019 2
1 2020 2
2 2018 3.5
2 2019 3.5
2 2020 3.5
2 2021 3.5