【发布时间】:2020-04-14 06:15:36
【问题描述】:
我有下面的 Json 字符串。我需要编写一个查询来获取 SP 记录。在不提供 索引值,我们需要得到结果。
{
"S": [
{
"Name": "Project1",
"SP": [
{
"ID": 1,
"Name": "Test1"
},
{
"ID": 2,
"Name": "Test2"
},
}]}
如何查询以获得 SP 值。
Expected Result:
ID Name
1 Test1
2 Test2
I tried the below but not working. Can you please suggest the correct query.
SELECT DISTINCT JSON_VALUE(JsonData, '$.S[0].SP.ID') AS ID,
JSON_VALUE(JsonData, '$.S[0].SP.Name') AS Name
FROM TableA
【问题讨论】:
-
您使用的是哪个 SQL 引擎?
-
我使用的是 SQL Server 2019
标签: sql json sql-server sql-server-2019