... it should add 12 columns with the same ID into another table.
Add COLUMNS? or rows? Presumably the latter, so imagine you have a table of numbers that run sequentially from 1 to 1000. Now imagine that you join your table (and where is your script that we can all use to write and test queries?) to this <table
of numbers> in some way. Your value column contains the upper limit - 1 is the assumed lower limit. The table contains a column with 1000 rows where the value of this column increases monotonically. How do you limit the join to get 12 rows for
john and 20 rows for sarah (etc.)?
You can find many suggestions for creating a table of number by searching. The script (welcome) below contains a simple version.
DECLARE @number_of_numbers INT = 50;
declare @tbl table (id int, name varchar(20), value smallint);
insert @tbl(id, name, value) values (1, 'john', 12), (2, 'sarah', 20), (3, 'tom', 5);
with numbers as (
select 1 as num
union all
select num + 1 from numbers where numbers.num <= 49
)
SELECT x.id, x.name, x.value, numbers.num
FROM @tbl as x inner join numbers
on x.value >= numbers.num
order by x.id, x.name, x.value, numbers.num
;