从 JSON - SQL 服务器获取值

Get values from JSON - SQL Server

我有以下 JSON:

[
  {
    "email_id": 1598819368,
    "email": "test01@abc.net"
  },
  {
    "email_id": 1598819369,
    "email": "test02@abc.net"
  },
  {
    "email_id": 1598819370,
    "email": "test03@abc.net"
  },
  {
    "email_id": 1598819371,
    "email": "test04@abc.net"
  }
]

如何使用 SQLServer 2017 return 仅包含电子邮件地址的列表?

-------------------
   emailaddress   
-------------------
  test01@abc.net
  test02@abc.net
  test03@abc.net
  test04@abc.net

我一直在尝试使用 JSON_VALUEJSON_QUERY,但我只能获得一个电子邮件地址或 NULL。

谢谢!

应该这样做

declare @json         nvarchar(max)=N'[
  {
    "email_id": 1598819368,
    "email": "test01@abc.net"
  },
  {
    "email_id": 1598819369,
    "email": "test02@abc.net"
  },
  {
    "email_id": 1598819370,
    "email": "test03@abc.net"
  },
  {
    "email_id": 1598819371,
    "email": "test04@abc.net"
  }
]'

select email from openjson(@json) with (email_id            bigint,
                                        email               nvarchar(200));

结果

email
test01@abc.net
test02@abc.net
test03@abc.net
test04@abc.net