Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Use of IIF in SQL command
Message
From
01/11/2001 12:40:12
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00576218
Message ID:
00576256
Views:
10
>Can somebody explain the following?
>
>Taking the Tastrade sample:
>Type the following in to the command window:
> SELECT * from supplier WHERE IIF(supplier_id < " 10",.T.,.F.)
>
>You get the records with ID's of 1 to 9
>
>If you add a not to it:
>SELECT * from supplier WHERE !IIF(supplier_id < " 10",.T.,.F.)
>
>I know that the expression "IIF(xxx,.T.,.F.)" is as even more pointless than "IF xxx = .T." but it was actually generated by a querying tool we have written. Of course, I could fix the problem, but I am intrigued since I am pretty sure that I am up against my own ignorance rather than a bug. Any intelligible explanation would be gratefully received!

Chris,
Not only with iif() but happens with similar functions like isnull(). If you force an evaluation than you get correct results.
For fun this returns what you expected :

SELECT * from supplier WHERE eval(IIF(supplier_id < " 10",'.T.','.F.'))

Or :
SELECT * from supplier WHERE IIF(supplier_id < " 10",.T.,.F.) = .t.

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform