From: Bob Barrows [MVP] on
Anthony Jones wrote:
> Note also that DATALENGTH returns null if the field passed to it as a
> parameter is null so you'll need to test that field with IsNull in
> VBScript
> code.

....or use " ... COALESCE(DATALENGTH(field),0) as fieldlength, ... " in the
sql statement.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


From: Dooza on
Bob Barrows [MVP] wrote:
> Anthony Jones wrote:
>> Note also that DATALENGTH returns null if the field passed to it as a
>> parameter is null so you'll need to test that field with IsNull in
>> VBScript
>> code.
>
> ...or use " ... COALESCE(DATALENGTH(field),0) as fieldlength, ... " in the
> sql statement.

So this basically checks if the datalength is null, and if it is, uses 0
instead, if its not it uses the datalength... I am starting to like
Coalesce more and more. In my ASP I would then check for 0 instead of NULL.

I am currently testing for null, is there any performance benefits to
using the above, or should I stick with what I have working at the moment?

Steve
From: Bob Barrows [MVP] on
Dooza wrote:
> Bob Barrows [MVP] wrote:
>> Anthony Jones wrote:
>>> Note also that DATALENGTH returns null if the field passed to it as
>>> a parameter is null so you'll need to test that field with IsNull in
>>> VBScript
>>> code.
>>
>> ...or use " ... COALESCE(DATALENGTH(field),0) as fieldlength, ... "
>> in the sql statement.
>
> So this basically checks if the datalength is null, and if it is,
> uses 0 instead, if its not it uses the datalength... I am starting to
> like Coalesce more and more. In my ASP I would then check for 0
> instead of NULL.

?
You should still check for 0 after checking for Null. The field could
contain a zero-length string ...

> I am currently testing for null, is there any performance benefits to
> using the above, or should I stick with what I have working at the
> moment?
It avoids having to do two checks in the vbscript code. Now all you have to
check for is 0.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


From: Dooza on
Bob Barrows [MVP] wrote:
> Dooza wrote:
>> Bob Barrows [MVP] wrote:
>>> Anthony Jones wrote:
>>>> Note also that DATALENGTH returns null if the field passed to it as
>>>> a parameter is null so you'll need to test that field with IsNull in
>>>> VBScript
>>>> code.
>>> ...or use " ... COALESCE(DATALENGTH(field),0) as fieldlength, ... "
>>> in the sql statement.
>> So this basically checks if the datalength is null, and if it is,
>> uses 0 instead, if its not it uses the datalength... I am starting to
>> like Coalesce more and more. In my ASP I would then check for 0
>> instead of NULL.
>
> ?
> You should still check for 0 after checking for Null. The field could
> contain a zero-length string ...
>
>> I am currently testing for null, is there any performance benefits to
>> using the above, or should I stick with what I have working at the
>> moment?
> It avoids having to do two checks in the vbscript code. Now all you have to
> check for is 0.

Of course, I should have been checking for empty but not null as well.
Your solution is working nicely.

Thank you Bob!

Steve
From: Dave Anderson on
"Anthony Jones" wrote:
> Note also that DATALENGTH returns null if the field passed
> to it as a parameter is null so you'll need to test that
> field with IsNull in VBScript code.

Only if you care about the difference between a zero-byte image and a null.
Otherwise, this type of construction is fine:

If RS.Fields("Bytes") > 0 Then ...



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.