An explanation of the IIF statement in SQL

Source: Internet
Author: User
Tags empty expression numeric sql string

Iif
Returns one of the two numeric or string values determined by the logical test.

Grammar
Digital
IIf («logical expression»,«numeric expression1»,«numeric expression2»)

If «logical expression» evaluates to TRUE, this function returns «numeric expression1», otherwise, returns «numeric expression2».

String
IIf («logical expression»,«string expression1»,«string expression2»)

If «logical expression» evaluates to TRUE, this function returns «string expression1», otherwise, returns «string expression2».

Comments
The expression is considered FALSE only if the value of the «logical expression» is zero. Any other value is interpreted as TRUE.
It is not recommended to use the IIF function to create a collection of members based on search criteria. Instead, use the Filter function to evaluate each member of the specified collection based on a logical expression, and then return a subset of the members.

Example
Digital
If the measures.currentmember is an empty cell, the following example returns 0, otherwise it returns 1:
IIf (IsEmpty (Measures.CurrentMember), 0, 1)

String
If Measures.CurrentMember is an empty cell, the following string returns the string "Yes", otherwise the string "No" is returned:
IIf (IsEmpty (Measures.CurrentMember), "Yes", "No")

In Access I can use the IIf function for statistical totals, for example, to know the number of users who should actually pay the fee:

1 2 Next page > full text reading tips: Try "←→" button, turn the page more convenient Oh!

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.