BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

NULL Concatenation Behavior

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Penny
Guest





PostPosted: Fri Oct 01, 2004 10:01 am    Post subject: NULL Concatenation Behavior Reply with quote



Hi,

I want to concatenate to strings, but both can be null.
e.g. 'AAA' + 'aaa' = 'AAAaaa'
'BBB' + null = 'BBB'

When I' m doing this I have
e.g. 'AAA' + 'aaa' = 'AAAaaa'
'BBB' + null = null

I found that this have to do with DBPROPVAL_CB_NULL, DBPROPVAL_CB_NON_NULL
but I can find how to change it.

Any ideas?

Thanks




Back to top
Martijn Tonies
Guest





PostPosted: Fri Oct 01, 2004 10:08 am    Post subject: Re: NULL Concatenation Behavior Reply with quote



Hello,

Quote:
I want to concatenate to strings, but both can be null.
e.g. 'AAA' + 'aaa' = 'AAAaaa'
'BBB' + null = 'BBB'

When I' m doing this I have
e.g. 'AAA' + 'aaa' = 'AAAaaa'
'BBB' + null = null

I found that this have to do with DBPROPVAL_CB_NULL, DBPROPVAL_CB_NON_NULL
but I can find how to change it.

Are you using MS SQL? If so, take a look at:
SET CONCAT_NULL_YIELDS_NULL { ON | OFF }

To change the behaviour, or, better yet:
COALESCE to change the NULL to an empty string:

'AAA' + COALESCE(someotherthing, '')


--
With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com



Back to top
Penny
Guest





PostPosted: Fri Oct 01, 2004 1:00 pm    Post subject: Re: NULL Concatenation Behavior Reply with quote



I use SQL Server 2000

I tried those :

use master
exec sp_dboption 'TestDB','concat null yields null','False'

and also

ALTER DATABASE StoresEmpty
SET CONCAT_NULL_YIELDS_NULL OFF

but it continues to result in Null.

COALESCE works but I don't want to change all my queries.

Moreover, I read from the help that default value of "concat null yields
null" is False,
so why that happens to me, that I surely never changed it.

Thanks.

"Martijn Tonies" <m.tonies@upscene!nospam!.com> wrote

Quote:
Hello,

I want to concatenate to strings, but both can be null.
e.g. 'AAA' + 'aaa' = 'AAAaaa'
'BBB' + null = 'BBB'

When I' m doing this I have
e.g. 'AAA' + 'aaa' = 'AAAaaa'
'BBB' + null = null

I found that this have to do with DBPROPVAL_CB_NULL,
DBPROPVAL_CB_NON_NULL
but I can find how to change it.

Are you using MS SQL? If so, take a look at:
SET CONCAT_NULL_YIELDS_NULL { ON | OFF }

To change the behaviour, or, better yet:
COALESCE to change the NULL to an empty string:

'AAA' + COALESCE(someotherthing, '')


--
With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS
SQL
Server.
Upscene Productions
http://www.upscene.com





Back to top
Martijn Tonies
Guest





PostPosted: Fri Oct 01, 2004 1:39 pm    Post subject: Re: NULL Concatenation Behavior Reply with quote

Quote:
I use SQL Server 2000

I tried those :

use master
exec sp_dboption 'TestDB','concat null yields null','False'

and also

ALTER DATABASE StoresEmpty
SET CONCAT_NULL_YIELDS_NULL OFF

Have another look at the Help. There's info on how to set this
on a per-database level and on a per-session level.



--
With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com



Back to top
Pravin Taneja
Guest





PostPosted: Fri Oct 01, 2004 2:27 pm    Post subject: Re: NULL Concatenation Behavior Reply with quote

Quote:

COALESCE works but I don't want to change all my queries.


You can create a view that uses COALESCE (to return '' for null fields) and
from your queries you use the view instead of the table name. This way you
wont have to change your program if you need to switch to another RDBMS but
you will have to write similar views using the syntax of target RDBMS to
achieve the same thing.

Pravin



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.