Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if record item = NULL 3

Status
Not open for further replies.

krymzon

Programmer
Feb 22, 2005
38
0
0
CA
i have a database, and all i need to do is check if the current record item is Null using a simple little if statement.

so its something like this

If rec("fieldname") = NULL then
response.write("some testing code")
End If

and sure, this is simple on concept, lol, but it won't seem to work. so, the question is can i check for NULL in this situtation. (Keep in mind i come from a advanced SQL background so i do know for a fact that the current record is NULL and there is other testing in place that makes sure this code will display correctly if it actually meets the critieria)

--there are 10 types of people in this world. those who know binary, and those who don't.--
 
Even Null does not Equal Null...

You want:
If IsNull(rec("fieldname")) Then ....
 
you need this to make sure that you take everything into consideration

If rec("fieldname") = "" AND ISNULL(rec("fieldname")) then

-DNG
 
ahhhhh. i see. wow, i should have known this from my good old days of college ASP.
now i feel like a rookie again, thanks guys...lol

--there are 10 types of people in this world. those who know binary, and those who don't.--
 
You can also use:

[tt]if rec("fieldname") & "" = "" then[/tt]


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I don't recommend the second suggestion (DNG) -- if it's NULL, why would you care if it's an empty string? If you want the comparison to hold true if it's null or it's an empty string, then use OR instead of AND. Otherwise I don't see that you gain anything, and you get a needless string comparison (which are expensive).

I don't recommend the the third one (TSD), either, as you're asking the parser to perform string concatenation where none is required if the item is null. If you're going for that "Null or Blank" thing, then DNG's version (with the OR) is better because you still have to deal with the string comparison either way, but at least you don't have to deal with the concatenation (also very expensive).

To sum, avoid string operations wherever possible, as they're quite pricey.

</oldfogey>
 
Thanks for the Correction Genimuse...

it should be

If rec("fieldname") = "" [red]OR[/red] ISNULL(rec("fieldname")) then

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top