可以在 Access 中使用 case
表达式吗?我试图确定 2 列的最大日期,但在以下代码中不断出现语法错误:
CASE
WHEN dbo_tbl_property.LASTSERVICEDATE > Contour_dates.[Last CP12 Date]
THEN dbo_tbl_property.LASTSERVICEDATE
ELSE Contour_dates.[Last CP12 Date]
END AS MaxDate
最佳答案
您可以改用IIF()
函数。
IIF(condition, valueiftrue, valueiffalse)
condition
是您要测试的值。valueiftrue
是条件评估为 TRUE 时返回的值。valueiffalse
是条件计算结果为 FALSE 时返回的值。
还有Switch
当您有多个条件需要测试时,该函数更易于使用和理解:
Switch( expr-1, value-1 [, expr-2, value-2 ] … [, expr-n, value-n ] )
The Switch function argument list consists of pairs of expressions and values. The expressions are evaluated from left to right, and the value associated with the first expression to evaluate to True is returned. If the parts aren't properly paired, a run-time error occurs. For example, if expr-1 is True, Switch returns value-1. If expr-1 is False, but expr-2 is True, Switch returns value-2, and so on.
Switch returns a Null value if:
None of the expressions is True.
The first True expression has a corresponding value that is Null.
NOTE: Switch evaluates all of the expressions, even though it returns only one of them. For this reason, you should watch for undesirable side effects. For example, if the evaluation of any expression results in a division by zero error, an error occurs.
关于sql - Access 中的大小写表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/772461/