Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

Null not detected in database field

Posted 30 Jan 2004 02:37:57
1
has voted
30 Jan 2004 02:37:57 Touti P posted:
Hi there,

All I'm doing is check to see if the value of a specific field is null. In my If Else statement below, it doesn't capture the NULLs:

If rsEvents("GroupID" = "" Then
....code.....
End If

If I do it the other way:

If rsEvents <> "" Then

Else
.....code.....
End If

Any ideas what's happening here? Thanks!

Replies

Replied 30 Jan 2004 16:01:19
30 Jan 2004 16:01:19 Lee Diggins replied:
Hi

My understanding is that "" will not check NULL data as NULL is an undetermined data value, whereas "" is an empty string and isn't the same as NULL.

Try utilising the IsNull VBScript function, I've pasted text from the v5.6 help file.

=================================

IsNull returns True if expression is Null, that is, it contains no valid data; otherwise, IsNull returns False. If expression consists of more than one variable, Null in any constituent variable causes True to be returned for the entire expression.

The Null value indicates that the variable contains no valid data. Null is not the same as Empty, which indicates that a variable has not yet been initialized. It is also not the same as a zero-length string ("", which is sometimes referred to as a null string.

Caution Use the IsNull function to determine whether an expression contains a Null value. Expressions that you might expect to evaluate to True under some circumstances, such as If Var = Null and If Var <> Null, are always False. This is because any expression containing a Null is itself Null, and therefore, False.
The following example uses the IsNull function to determine whether a variable contains a Null:

Dim MyVar, MyCheck
MyCheck = IsNull(MyVar) ' Returns False.
MyVar = Null ' Assign Null.
MyCheck = IsNull(MyVar) ' Returns True.
MyVar = Empty ' Assign Empty.
MyCheck = IsNull(MyVar) ' Returns False.

=================================

Another way (in SQL anyway) is using the ISNULL() in your select statement, not sure if you have this function available in your db though so you need to check it out.

If you have a column that can contain NULL then you can do something like this to send your NULL as something you specify, like this:

select isnull(price, 0.00) from tbl_products

This function will replace the NULL found with 0.00, you could change the 0.00 to anything you like and then get your IF statement to check against the replacement value of NULL

select ISNULL(MyData, 'NullValue') from tbl_data

This will send the text NullValue in place of the NULL returned in the recordset for the column MyData, note the single quotes around text, not needed for numeric replacement as show in the ISNULL example.

Hope this helps

Digga

Sharing Knowledge Saves Valuable Time!!!
Replied 05 Feb 2004 20:12:10
05 Feb 2004 20:12:10 Touti P replied:
It works! Thank you so much for being so helpful!!!

Reply to this topic