在IIF语句中使用存在子句

时间:2018-07-23 19:20:18

标签: ms-access

我们可以在IIF语句中使用Exists子句吗?我想根据特定条件订购输出。

Select *
From Table1 AS a
Order By IIF( Exists(Select * From Table2 Where Col_Name='Criteria'),a.Col1,a.Col2) Desc

无法在MS Access中获得结果。

1 个答案:

答案 0 :(得分:1)

DLookUpDCount域功能视为EXISTS子句,在MS Access表达式中不起作用:

Select *
From Table1 AS a
Order By IIF(DLookUp("Col_Name", "Table2", "Col_Name='Criteria'") IS NOT NULL, a.Col1, a.Col2) Desc

Select *
From Table1 AS a
Order By IIF(DCount("*", "Table2", "Col_Name='Criteria'") > 0, a.Col1, a.Col2) Desc