首页 > 解决方案 > 即使在 where in 子句中的条件为空,如何返回结果集

问题描述

我正在尝试将多个 where-in 子句链接在一起,并且当其中一个返回时遇到问题null

如果 where in 产生 anull我想忽略它。

declare @json nvarchar(max) = '
[
  {
    "key": "A",
     "value": ["1","2"]
  }, {
    "key": "B"
  }, , {
    "key": "C"
  }
]';

select *
from someTable]
where col1 in (select value from openjson(@json, '$[0].value'))
and col2 in (select value from openjson(@json, '$[0].value')) -- returns null, so empties query
and col3 in (select value from openjson(@json, '$[1].value')) -- returns null, so empties query

where当集合为空时,我将如何从结果集中省略?

标签: sqljsonsql-serverwhere-clausewhere-in

解决方案


推荐阅读