简体   繁体   English

SQL MS-Access 中带有 IIF 和 IsNull 的动态 Where 条件

[英]Dynamic Where conditions with IIF and IsNull in SQL MS-Access

Is it possible to write the WHERE clause with an IIF and an IsNull condition in SQL MS-ACCESS?是否可以在 SQL MS-ACCESS 中编写带有 IIF 和 IsNull 条件的 WHERE 子句? ie: IE:

SELECT Table1.colx,.... FROM ((Table1 INNER JOIN Table2 ON Table1.col1=Table2.col1) INNER JOIN Table3 ON Table3.col2=Table2.col2) WHERE IIF(IsNull(Table1.colx='someValue1'),Table1.colx='someValue2',Table1.colx='someValue1') SELECT Table1.colx,.... FROM ((Table1 INNER JOIN Table2 ON Table1.col1=Table2.col1) INNER JOIN Table3 ON Table3.col2=Table2.col2) WHERE IIF(IsNull(Table1.colx='someValue1') ,Table1.colx='someValue2',Table1.colx='someValue1')

You pretty much never want to use IIF in a WHERE clause.您几乎不想在WHERE子句中使用IIF Just use AND , OR , and parentheses.只需使用ANDOR和括号。

From your comment, the solution seems simple:从您的评论来看,解决方案似乎很简单:

WHERE (TablTe1.colx='someValue1' AND Table1.colx='someValue2' AND TablTe1.colx='someValue1')
OR  ((TablTe1.colx <> 'someValue1' OR Table1.colx <> 'someValue2') AND  Table1.colx='someValue2')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM