Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IIF()
Message
From
30/04/1998 11:42:53
 
 
To
27/04/1998 12:33:54
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Re: IIF()
Miscellaneous
Thread ID:
00095089
Message ID:
00096007
Views:
51
>>Hello,
>> Is an IIF() faster than an If-Else-Endif statement?
>
>As with most things in life, it depends on your definition of "faster." As several others have mentioned, there is a negligible speed difference if you are using simple expressions [=IIF(x==y, value1, value2]. Complex expressions that have nested IIFs and subfunctions are a little trickier.
>
>However, I find that the real advantage to IIF() is it's ease of use in SELECT statements. One of my favorite code algorithms is to have several optional fields on my query form, and based on what the user enters, filter my select like so:
>
>SELECT table1.x, table1.y, table1.z ;
>FROM table1 ;
>WHERE EVAL(IIF(!EMPTY(field1), "x = field1","")) ;
>AND EVAL(IIF(!EMPTY(field2), "y = field2",""))
>INTO CURSOR csrResults
>
>When you have four or five fields on a form, and you don't want to create a WHEN string that will be macro-expanded, this approach is a beauty, and actually does execute faster than a macro-expanded string (at least it did under 2.6; haven't had need to try it under VFP).

Bill,
I'm hoping you will elaborate on your use of EVAL in the above SQL where clause.
If you remove the IIF function from the expression you get something like:
EVAL("y=field2"). When I try this at the command line, even where y and field2 have previously been defined, I get an error message. I always thought EVAL forces evaluation of an expression and returns the result. Wouldn't evaluating the expression y=field2 yield a .T. or .F. depending upon the value of each of those variables.
Thanks for you help.
-Dore
Previous
Reply
Map
View

Click here to load this message in the networking platform