Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP9 and null values and NVL()
Message
From
25/07/2006 11:21:35
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
 
To
25/07/2006 09:00:53
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01139317
Message ID:
01139735
Views:
27
>I see that now. Basically we have a bit field in SQL that is used for logical values. It allows nulls and the default value is false. Of course, it is a new field which we had with the update and new default values are set to false but existing records are left as null during the update. The majority of the records will have a null value. In most cases, we pull the record only if it is false or null, but not true. In our Select statemens we have:
>
>(ISNULL(inactive,0)!=1)
>
>when the result returned is filtered on only returning records that are not marked as inactive. Many times we have the field in a different result set though based on other queries and in that case we step through the result set in VFP and use:
>
>IF !(NVL(logicalfield,.F.)) && check for false
>
>or
>
>IF (NVL(logicalfield,.F.)) && check for true
>
>It looked in testing as if the nulls were behaving as false (which would be fine since the default value in the field is false) and didn't require the NVL(). I just wanted to be sure whether or not that would
>always be the case. In other words:
>
>IF !logicalfield && check for false
>
>appeared to work as well when the value was null and not false. I couldn't be certain though based on my limited understanding of how VFP handles null values in cursors. I was playing it 'safe' with the NVL() I think. I tested 65,000,000 records using both methods and the speed difference between the two was negligible. I've had strange result sets returned when the very first record returned contained a null value though (VFP would sometimes created a different field type instead of a logical field) so I wanted to be sure.

Here's a simple test:

?IIF(null, "true","false")
?IIF(not null, "true","false")

both return "false". Also,
IF null
	? "true"
ELSE
	? "false"
endif
does the same (also with not null). I'd just conclude that a logical expression behaves as false if it evaluates to null.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform