You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在PowerShell的OData URI $filter中添加类似SQL的NOT IN语句(适用于Business Central)

在Microsoft Business Central的OData $filter中实现NOT IN逻辑

OData规范本身没有提供NOT IN这类直接运算符,但可以通过两种等价的逻辑组合,实现和SQL中Brand NOT IN ('A','B','C','D')完全一致的过滤效果:

方式1:多个ne(不等于)的逻辑与

将每个需要排除的品牌值用ne判断,再用and串联所有条件:

...?$filter=(Web eq ''N'' or Web eq ''W'') and Item_Type ne ''I'' and Brand ne ''A'' and Brand ne ''B'' and Brand ne ''C'' and Brand ne ''D'''

方式2:not包裹多个eq的逻辑或

先把需要排除的品牌值用eq和or组合成“命中任一排除值”的条件,再用not取反:

...?$filter=(Web eq ''N'' or Web eq ''W'') and Item_Type ne ''I'' and not (Brand eq ''A'' or Brand eq ''B'' or Brand eq ''C'' or Brand eq ''D''))'

注意点

  • 两种写法在Business Central的OData服务中均有效,可根据可读性需求选择
  • 保持和你原有脚本一致的转义规则:PowerShell中用两个单引号''转义字符串内的单引号

内容的提问来源于stack exchange,提问作者johnrpg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 05:45:36