IF Clause

OLE DB Programmer's Reference

The IF clause, IIF, can be used to test any search condition and choose one value or another based on whether the test is true or false. The BNF form is as follows:

<if_expression> ::= IIF(<search_condition>, <true_part>, <false_part>) <true_part> ::= <value_expression> <false_part> ::= <value_expression>

The data type of <true_part> must be the same as the data type of <false_part>. That is, either both are numeric value expressions or both are string value expressions.

The following example demonstrates the use of IIF. The query displays actual sales, budgeted sales, and variance (that is, the difference between actual and budgeted sales) for Asia and Europe for each quarter of 1991, for all sales reps and all products. The conditional expression is used to keep the variance always positive.

WITH MEMBER [Measures].[Variance] AS IIF ((Sales > BudgetedSales),    (Sales - BudgetedSales), (BudgetedSales - Sales)) SELECT    {Sales, BudgetedSales, Variance} ON COLUMNS,    CROSSJOIN({Asia, Europe}, {Qtr1, Qtr2, Qtr3, Qtr4}) ON ROWS FROM SalesCube WHERE ([1991], [SalesRep].[ALL], [Products].[ALL])

1998-2001 Microsoft Corporation. All rights reserved.



Microsoft Ole Db 2.0 Programmer's Reference and Data Access SDK
Microsoft OLE DB 2.0 Programmers Reference and Data Access SDK (Microsoft Professional Editions)
ISBN: 0735605904
EAN: 2147483647
Year: 1998
Pages: 1083

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net