0

试图在 MS SQL 2016 中实现以下工作,但需要 MS SQL JSON 专家来提供帮助。

我在文本字符串中有一个带有 JSON 的表

  [
  {
    "static-list-id": 37,
    "internal-list-id": 41,
    "timestamp": 1554831874747,
    "vid": 9350104,
    "is-member": true
  },
  {
    "static-list-id": 39,
    "internal-list-id": 43,
    "timestamp": 1554831874931,
    "vid": 9350104,
    "is-member": true
  }
  ]'

这是我的 SQL 语句,我想我可能需要一个 JSON_QUERY

SELECT 
    JSON_VALUE([MyNVarCharWithJSONColumn],'strict $."static-list-id"') AS static_list_id
FROM
  [MyTable] C
  WHERE ISJSON([MyNVarCharWithJSONColumn])>0

这些是我想从 SQL 语句中得到的结果,每行一行

static_list_id
--------------
37
39

非常感谢您的帮助

4

1 回答 1

2

你可以使用:

SELECT a.static_list_id
FROM MyTable 
CROSS APPLY OPENJSON(MyNVarCharWithJSONColumn)
WITH (static_list_id INT N'$."static-list-id"') AS a;

db<>小提琴演示

于 2019-04-10T22:10:58.250 回答