Hi.
This question is in regard to using datalength() on a text or image column that allows nulls.
For decades now, going back probably to Sybase SQL Server version 4, I have used datalength() to tell if a text/image column is null. If that returns 0, it's null. This is true up through ASE 15.0. But now I observe in ASE 16.0 that datalength() returns NULL when given a null text/image column. I'm guessing that datalength() will no longer return 0 under any circumstances. This causes some of my existing T-SQL code to break.
I've checked the manual, and it says "datalength of any NULL data returns NULL". That's fine, but it also says that in the ASE15.0 manual, and indeed all the way back to the 11.5 manual (which is the oldest one I have easy access to). So apparently for a long, long time the manual did not correspond to the behavior. And instead of fixing the ASE16 manual to match the behavior, Sybase apparently fixed the behavior to match the manual. This is annoying. In my long experience with Sybase it's extremely rare for a new ASE version to break my existing T-SQL code.
I googled this topic and didn't find anything, which surprises me because wouldn't most people dealing with text or image columns experience this same problem when moving up to ASE16?
My first question is, is there an option to revert the behavior in ASE16 to match the old behavior? If not, then my second question is what should I do about this?
I'm thinking that in a pure ASE16 environment, I can just test for the function returning null, or even better I can now test the text/image value directly, like one of the following:
where datalength(text) is null
or...
where text is null
But for a while I will be in a mixed ASE15/16 environment, where I have a common base of source code that's intended to work in both versions. So I think I could do this:
where isnull(datalength(text),0)=0
And that should work reliably in any version of ASE (even if Sybase ever decides to change the behavior BACK to what it was).
Any other advice for me?
Thanks.
- John.