1

Topic: Dynamic insertion of lines

Greetings the people!
Help with request SQL.
There is a table. In the table one of columns has the data with an amount of lines (Lota) is an amount of clones of lines.
[code]
[code] Initial Result
No  Lota No  Lota
9.992 2 9.992-1 2
89.11 2 9.992-2 2
89.138 3 89.81-1 2
89.81-2 2
89.138-1 3
89.138-2 3
89.138-3 3
[/code] [/code]
It is necessary to write request which interposed clones of the lines which amount is specified in a column prizes, and to rename values in a column No . -1, the second-2 etc.

2

Re: Dynamic insertion of lines

;with
T (id, rpz, lots) as
(
select
id, rpz, lots
from (values (1, ' 9.992 ', 2), (2, ' 89.11 ', 2), (3, ' 89.138 ', 3)) t (id, rpz, lots)
);
N1 (n) as
(
select top 3
row_number () over (order by s1.object_id)
from
sys.objects as s1
cross join sys.objects as s2
);
N2 (n1, n2) as
(
select
n1.n, n2.n
from
N1 n1
inner join N1 n2 on n2.n <= n1.n
)
select
t.rpz + ' - ' + cast (n.n2 as char (1)) as rpz;
t.lots
from
T t
inner join N2 n on n.n1 = t.lots
order by
t.id, n.n2