T-SQL:如何解析JSON数组并提取单个属性值?

daupos2t  于 2023-03-13  发布在  其他
关注(0)|答案(1)|浏览(182)

鉴于:

SELECT * FROM OPENJSON(JSON_QUERY('[{"JobId":"2838","Options":1}, {"JobId":"2839","Options":1}]'))

给我们:

key value                           type
0   {"JobId":"2838","Options":1}    5
1   {"JobId":"2839","Options":1}    5

如何更改查询以返回作业ID?

value
2838
2839
hs1ihplo

hs1ihplo1#

这个应该可以了

SELECT JobId
FROM OPENJSON('[{"JobId":"2838","Options":1}, {"JobId":"2839","Options":1}]')
WITH (JobId INT N'$.JobId');

相关问题