DECLARE @json_str NVARCHAR(MAX) =
'{"Customers":
[{"Id":1,"Name":"Basavaraj",
"Address":{"State":"KA","Country":"India"}},
{"Id":2,"Name":"Kalpana",
"Address":{"State":"NY","Country":"United State"}}
]
}'
SELECT JSON_QUERY(@json_str,'$.Customers[0].Address') AddressObject
如果我们执行上述查询,则返回Customers Address对象。
{ “状态”: “KA”, “国家”: “印”}
我想根据属性
获取单个Customer对象DECLARE @json_str NVARCHAR(MAX) =
'{"Customers":
[{"Id":1,"Name":"Basavaraj",
"Address":{"State":"KA","Country":"India"}},
{"Id":2,"Name":"Kalpana",
"Address":{"State":"NY","Country":"United State"}}
]
}'
SELECT JSON_QUERY(@json_str,'$.Customers[].State') AddressObject where AddressObject="NY"
{“State”:“NY”,“Country”:“United State”}
我们可以在SQL Server 2016中执行此操作吗?