Home page
 
 Home 
 ASP 
 PHP 
 SQL 
 HTML 
 JavaScript 
 Search 
 Contact 
 
Search
or browse popular tags
Access Functions
Subscription

Sign up for the free email newsletter for new tips, tutorials and more. Enter your email address below, and then click the button.

Privacy Policy

RSS Twitter

Access: IIF Function

Print

In Access, the IIF function returns one of two arguments depending on the evaluation of an expression.

The syntax for the IIf function is:

IIf ( expression, truepart, falsepart )

IIf always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True.

expression is the value that you want to test.

truepart is the value returned if expression evaluates to TRUE.

falsepart is the value returned if expression evaluates to FALSE.

Example

IIf ([Price] > 400, "expensive", "cheap")      Returns "expensive" if the value in the Price field is
                                               greater than 400. Otherwise, returns "cheap".

VBA Code

If [Price] > 400 Then
 result="expensive"
Else
 result="cheap"
End If

This is equivalent to the following IF statement in VBA code. The preceding example uses the IIf function to evaluate the givven expression and returns the word "Expensive" if the amount is greater than 400; otherwise, it returns the word "Cheap".

SQL query

You can also use the iif function in a query.

SELECT SellerID, BuyerID, Item, IIf([Price]>400,[Price]*1.05,[Price]*1.15) AS Total
FROM Antiques


If you'd like to see how it works, enter SQL statement and press Execute
 




Tags:

Add To: Add to dzone dzone | Digg this digg | Add to del.icio.us del.icio.us | Stumble it stumbleupon

  • Comments





Copyright © 2005-2014             www.WebCheatSheet.com All Rights Reserved.