2
supposons que vous avezConstruire JSON avec le paramètre clé variable/variable de json_modify 2ème
create schema tmp
go
create table tmp.Properties
(
ParentId uniqueidentifier not null,
PropertyName nvarchar(20) not null,
PropertyValue nvarchar(100) null,
primary key (ParentId,PropertyName)
)
go
create table tmp.FullData
(
ParentId uniqueidentifier not null,
Properties nvarchar(max) null,
primary key (ParentId)
)
go
declare @id1 uniqueidentifier = 'F1935D6A-D5A6-4FA1-ACF4-BA3858804CEC',
@id2 uniqueidentifier = 'F1935D6B-D5A6-4FA1-ACF4-BA3858804CEC'
insert into tmp.Properties
values
(@id1, 'FirstName', 'Luke'),
(@id1, 'LastName', 'Skywalker'),
(@id2, 'FirstName', 'Han'),
(@id2, 'LastName', 'Solo')
s'il vous plaît considérer que:
- propriétés sont créées dynamiquement et je ne peux pas savoir à l'avance PropertyNames
- au moment parents table contient 1M et propriétés table contient 23M enregistrements
comment puis-je remplir tmp.FullData avec:
ParentId Properties
------------------------------------ ------------------------------------------------
F1935D6A-D5A6-4FA1-ACF4-BA3858804CEC { "FirstName": "Luke", "LastName": "Skywalker" }
F1935D6B-D5A6-4FA1-ACF4-BA3858804CEC { "FirstName": "Han", "Test1": "Solo" }
J'ai essayé
insert into tmp.FullData (ParentId, Properties)
select distinct ParentId, '{}' from tmp.Properties
update f
set Properties = json_modify(Properties, 'append $.' + p.PropertyName, p.PropertyValue)
from tmp.FullData f
cross join tmp.Properties p
mais comme vous le savez/imaginer
Msg 13610, Level 16, State 2, Line 39
The argument 2 of the "JSON_MODIFY" must be a string literal.
une autre option? merci à l'avance