Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Enterprise
Expertise: Advanced
Dec 21, 2001

Control the Concatenation Results in SQL Server


You can control the concatenation results using SQL Server CONCAT_NULL_YIELDS_NULL(T-SQL). Depending upon the CONCAT_NULL_YIELDS_NULL settings, the concatenation results are treated as null or empty string values. When SET CONCAT_NULL_YIELDS_NULL is ON, concatenating a null value with a string yields a NULL result. When SET CONCAT_NULL_YIELDS_NULL is OFF then the null value is treated as an empty string. Concatenating a null value with a string yields the string itself.

For Example:
 
SET CONCAT_NULL_YIELDS_NULL ON


declare @firstname varchar(15)
declare @lastname varchar(15)

select @firstname='Bush'
select @lastname=null


select @firstname+@lastname

Result:
 
NULL


SET CONCAT_NULL_YIELDS_NULL OFF


declare @firstname varchar(15)
declare @lastname varchar(15)

select @firstname='Bush'
select @lastname=null


select @firstname+@lastname

Result:
 
Bush
Srinivas Reddy
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date