Access中的大小写表达式 [英] Case expressions in Access

查看:99
本文介绍了Access中的大小写表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在Access中使用case表达式吗?我正在尝试确定最大日期表单2列,但在以下代码中不断出现语法错误:

Can you use case expressions in Access? I'm trying to determine the max date form 2 columns but keep getting syntax errors in the following code:

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是您要测试的值.

    • condition is the value that you want to test.

      valueiftrue是条件评估为TRUE时返回的值.

      valueiftrue is the value that is returned if condition evaluates to TRUE.

      valueiffalse是条件评估为FALSE时返回的值.

      valueiffalse is the value that is returned if condition evaluates to FALSE.

      还有 函数,当您有多个条件要测试时,该函数更易于使用和理解:

      There is also the Switch function which is easier to use and understand when you have multiple conditions to test:

      Switch( expr-1, value-1 [, expr-2, value-2 ] … [, expr-n, value-n ] )
      

      Switch函数参数列表由成对的表达式和 价值观.表达式从左到右进行求值,并且 与第一个表达式的值关联为True的值是 回来.如果零件未正确配对,则会出现运行时错误 发生.例如,如果expr-1为True,则Switch返回value-1.如果 expr-1为False,而expr-2为True,Switch返回value-2,依此类推 上.

      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.

      在以下情况下,开关将返回Null值:

      Switch returns a Null value if:

      • 所有表达式都不是True.

      • None of the expressions is True.

      第一个True表达式的对应值为Null.

      The first True expression has a corresponding value that is Null.

      注意:即使只返回其中一个,Switch也会计算所有表达式.因此,您应该注意 不良的副作用.例如,如果评估任何 表达式导致被零除的错误,发生错误.

      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.

      这篇关于Access中的大小写表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆