How to use JSON_VALUE in where in clause (SQL Server)

Matthew :

: am trying to use part of a JSON to use as a filter for a where in clause as follows:

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'));

How do I convert the value into a where-in argument?

David Browne - Microsoft :

Like this:

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

select value from openjson(@json, '$[0].brand_name.value')

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=397455&siteId=1