I begin with SQL Server. I first wrote a query which creates a table. With this table I would like to add some rows.
The code below creates the table.
select
Element = [Key],
New = max(case when time_index=1 then value end),
'Current' = max(case when time_index>=2 then value end)
from
(select
[time_index], B.*
from
(select *
from ifrs17.output_bba
where id in (602677, 602777)) A
cross apply
(select [Key], Value
from OpenJson((select A.* FOR JSON PATH, WITHOUT_ARRAY_WRAPPER))
where [Key] not in ('time_index')) B
) A
group by
[Key]
The result is here
Element | New | Current |
---|---|---|
AAA | 10 | 20 |
BBB | 15 | 34 |
CCC | 17 | 22 |
Now, I would like to (for example) duplicate the second row ("BBB") and change the name ("Element") by "DDD".
Element | New | Current |
---|---|---|
AAA | 10 | 20 |
BBB | 15 | 34 |
CCC | 17 | 22 |
DDD | 15 | 34 |
Do you have an idea how to proceed?