[thelist] Friday Freebie

Scott Dexter sgd at ti3.com
Fri Nov 3 14:45:25 CST 2000

> >   '*** Casting the right types. look ma, I'm in pictures!!
> >   uid = CLng(oRS(0))
> would not this cause errors if the field is NULL? Could you do:
> uid = oRS(0)
> if not isNull(uid) then uid=clng(uid) else uid=-1

Good catch, Matt. Yes, any of the casting functions that cast to a numeric
type will puke if the value is Null. The If...then...else statement above
will get around it, though you could also rely on the db to do work for you
(IMHO you should, that's why its there):

Select isnull(uid,0) ...

the (MS SQL Server) isnull function allows you to specify a return value if
the field is Null. Check your local db's documentation for it, I'm not sure
if its standard sql or an MS add-on....

> way, or do you have to access the recordset twice:
> if not isNull(oRS(0)) then uid=clng(oRS(0)) else uid=-1

Note you *could* do it this way and still have it work, but accessing the
recordset twice is wasteful; use one of the above instead....

Thanks Matt, for reminding me to test my code before sending ;)

think safely (yeah, me too)

More information about the thelist mailing list