0
SQL Server 2016でJSON機能を使用しています。変数を使用して、$ .people []配列の項目を以下のように参照するにはどうすればよいですか? JSON_QUERY関数のpathパラメーターに "1"をハードコーディングする代わりに、変数を使用してpeople配列の各項目をループしたいと思います。T-SQLでjsonオブジェクトの配列項目を参照する方法
declare @json nvarchar(max) = '{
"people": [{
"name": "John",
"surname": "Doe"
}, {
"name": "Jane",
"surname": null,
"active": true
}]
}';
select JSON_QUERY(@json,'$.people[1]'); -- this works
declare @test nvarchar(max) = '$.people[1]';
select JSON_QUERY(@json,@test); -- ERROR: The argument 2 of the "JSON_VALUE or JSON_QUERY" must be a string literal.