Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 concatenate with null value

Author  Topic 

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-08-29 : 00:50:16
hi

I have a table:

ID Address1 Address2 Address3 Person
1 demo demo null john
2 street main demo Kent


When i tried using Select ID, Address1+Address2+Address3, Person from tableA

It gives me

1 null John
2 streetmaindemo Kent

What i want is
1 demodemo John
2 streetmaindemo Kent


How can i still able to concatenate values even if there is a null column? Thanks

pakko
Starting Member

6 Posts

Posted - 2009-08-29 : 02:34:28

Hi,

I think ISNULL will do the job:

Select ID, ISNULL(Address1,'')+ISNULL(Address2,'')+ISNULL(Address3,''), Person from tableA

pakko
Go to Top of Page

sg2255551
Constraint Violating Yak Guru

274 Posts

Posted - 2009-08-29 : 11:34:51
Thanks. It works
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-31 : 02:15:40
or use COALESCE instead of isnull

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -