我们正在使用 Azure SQL,并有一个名为 Companies 的表,其中一列包含 JSON。 JSON 字段的结构为:
{
"DepartmentLink": "https://company.com",
"ContactName": "John Doe",
"ContactTitle": "CEO",
"ContactEmail": "[email protected]",
"ContactPhone": "xx xx xx xx xx",
"ContactImage": "https://company.com/xyz.jpg",
"ZipCodes": [
"7000",
"7007",
"7017",
"7018",
"7029"
]
}
表的结构如下所示
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](100) NULL,
[JsonString] [nvarchar](max) NULL,
-- other fields --
其中 [JsonString] 具有以下结构:
{
"DepartmentLink": "https://company.com",
"ContactName": "John Doe",
"ContactTitle": "CEO",
"ContactEmail": "[email protected]",
"ContactPhone": "xx xx xx xx xx",
"ContactImage": "https://company.com/xyz.jpg",
"ZipCodes": [
"7000",
"7007",
"7017",
"7018",
"7029"
]
}
给定一个邮政编码,例如7018 我需要找到在 Json Array ZipCodes 中具有此 ZipCode 的公司 - 并从记录中返回元素(这些元素都作为普通“字段”出现 - 所以我不需要返回 JSON。)。
我在寻找如何执行此操作时遇到问题。有什么建议么?我对 SQL 中的 JSON 很陌生。