Does MS Access support “CASE WHEN” clause if connect with ODBC?

前端 未结 3 1783
小鲜肉
小鲜肉 2020-11-27 07:07

Does ODBC support CASE WHEN clause for MS Access? Is there any other database which does not support the CASE WHEN clause? I tried the following qu

相关标签:
3条回答
  • 2020-11-27 07:47

    Since you are using Access to compose the query, you have to stick to Access's version of SQL.

    To choose between several different return values, use the switch() function. So to translate and extend your example a bit:

    select switch(
      age > 40, 4,
      age > 25, 3,
      age > 20, 2,
      age > 10, 1,
      true, 0
    ) from demo
    

    The 'true' case is the default one. If you don't have it and none of the other cases match, the function will return null.

    The Office website has documentation on this but their example syntax is VBA and it's also wrong. I've given them feedback on this but you should be fine following the above example.

    0 讨论(0)
  • 2020-11-27 08:00

    I have had to use a multiple IIF statement to create a similar result in ACCESS SQL.

    IIf([refi type] Like "FHA ST*","F",IIf([refi type]="VA IRRL","V"))
    

    All remaining will stay Null.

    0 讨论(0)
  • 2020-11-27 08:07

    You could use IIF statement like in the next example:

    SELECT
       IIF(test_expression, value_if_true, value_if_false) AS FIELD_NAME
    FROM
       TABLE_NAME
    
    0 讨论(0)
提交回复
热议问题