【问题标题】:How to use JSON_VALUE in where in clause (SQL Server)如何在 where in 子句中使用 JSON_VALUE (SQL Server)
【发布时间】:2020-07-15 20:26:14
【问题描述】:

:我正在尝试使用 JSON 的一部分作为 where in 子句的过滤器,如下所示:

declare @json nvarchar(max) = 
'[{
  "brand_name": {
    "key": "Brand Name",
    "value": "''alpha'',''omega''"
  }
}]';

select *
from someTable
where column in (select json_value(@json, '$[0].brand_name.value'));

如何将value 转换为 where-in 参数?

【问题讨论】:

    标签: json sql-server where-clause where-in


    【解决方案1】:

    像这样:

    declare @json nvarchar(max) = 
    '[{
      "brand_name": {
        "key": "Brand Name",
        "value": ["alpha","omega"]
      }
    }]';
    
    select value from openjson(@json, '$[0].brand_name.value')
    

    【讨论】:

    • 太棒了。再次感谢大卫!
    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多