如何在 where in 子句中使用 JSON_VALUE (SQL 服务器)
How to use JSON_VALUE in where in clause (SQL Server)
:我正在尝试使用 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 参数?
像这样:
declare @json nvarchar(max) =
'[{
"brand_name": {
"key": "Brand Name",
"value": ["alpha","omega"]
}
}]';
select value from openjson(@json, '$[0].brand_name.value')
:我正在尝试使用 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 参数?
像这样:
declare @json nvarchar(max) =
'[{
"brand_name": {
"key": "Brand Name",
"value": ["alpha","omega"]
}
}]';
select value from openjson(@json, '$[0].brand_name.value')