I've tried to reproduce your error, and can't do so. I created a table and populated it thus:
create table tab3
( t1 varchar(255)
, t2 varchar(255)
)
insert into tab3 values ('1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',null);
insert into tab3 values ('1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890','abcdefghijklmnopqrstuvwxyz');
By running the query:
select t1
+ case when t2 is null then ''
else t2 end
from tab3
I get the correct data in both rows. My test query was through Query Analyser. So, a couple of questions:
1. Does my simple test replicate your situation?
2. Are you testing through Query Analyser?
It strikes me that maybe you are (either directly or indirectly) allocating storage based on the data returned from the first row and thus are truncating subsequent data. I've seen this sort of problem with badly written ODBC drivers, although I doubt the SQL Server ODBC would have problems with something so simple. I wonder what the metadata says for the row set (either the SQLDA or recordset properties collection depending on your connection mechanism).
As an aside, for this type of conditional test I'd guess that the COALESCE function is more effecient, and possibly more stable!
Regards
Martyn Hodgson
martyn.hodgson@cdesolutions.com