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
 General SQL Server Forums
 New to SQL Server Programming
 Concatenating two or more field values

Author  Topic 

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2010-05-20 : 12:05:52
Hi

I have three fields from a table (all varchar) that I am trying to concatenate in a procedure but when I add the third field all it does is return nulls?

Code is like this:

Select
.......,
.......,
(Field1 + Field2 + Field3) AS ConcatField
From Table1

As I said it is ok until I add the third field.

Thanks

G

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-05-20 : 12:17:24
Field3 should contain NULLS. Check out the ISNULL or the COALESCE function.
Go to Top of Page

flamblaster
Constraint Violating Yak Guru

384 Posts

Posted - 2010-05-21 : 05:00:54
Select coalesce(field1,'')+coalesce(field2,'')+coalesce(field3,'')
from table1

should work
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-05-21 : 05:52:25
We can use coalesce for multiple option!

Here isnull() will play a better role!

Select isnull(field1,'')+isnull(field2,'')+isnull(field3,'')
from table1


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2010-06-16 : 11:09:32
Thanks, used is null.
Go to Top of Page
   

- Advertisement -