Case Statement in Access SQL


In Access, we can’t use CASE statement.

Alternatively, we can use Switch statement.

Usage

The above code was written with Switch as follows.

It was said that Access employs Switch because of compatibility with VBA, but I don’t know actual reason.

Use iif

You can also use Iif. The following code leads same result.

Use Choose

It is a choice to use Choose, in some cases.

index に整数を入れると、index = 1 なら a が、 index = 2 なら b が返ります。 整数でない場合は、一番近い整数に丸められます。 If index is less than 1, Null is returned.