Ways to replace case when in Access

Source: Internet
Author: User

Recently doing an east with access, which uses the way case, but access does not support this syntax, query know IIF and Swith can be substituted, summarized as follows:

IIf (expr, Truepart, Falsepart)


The IIF function syntax contains the following named arguments:
Section description
The necessary parameters for expr. An expression used to determine authenticity.
Truepart necessary parameters. If expr is True, the value or expression of this part is returned.
Falsepart necessary parameters. If expr is False, the value or expression for this part is returned.

Instance:

SELECT q_sellout.*,
IIF (sell_month= ' 1 ' or sell_month= ' 2 ' or sell_month= ' 3 ', ' Q1 ', IIf (sell_month= ' 4 ' or sell_month= ' 5 ' or sell_month= ' 6 ', ' Q2 ', IIF (sell_month= ' 7 ' or sell_month= ' 8 ' or sell_month= ' 9 ', ' Q3 ', IIF (sell_month= ' or sell_month= ' one ' or sell_month= ') ' Q4 ', ' Error ')))) as Acct_quarter
From Q_sellout;

The above implementation is to find out which quarter a month belongs to.

Additional switch mode:

SELECT UserID,
UserName,
SWITCH (
Sex = ' f ', ' male ',
Sex = ' m ', ' woman ',
True, ' confidential '
) as Sexname
From TUser
The last case in the above is true, and the usage is similar to the else in case syntax.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.