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

时间:2019-05-31 16:41:08

标签: arrays json sql-server tsql

鉴于:

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

1 个答案:

答案 0 :(得分:3)

这应该做

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