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
 Combine 2 column in 1

Author  Topic 

jimmy2090
Starting Member

26 Posts

Posted - 2015-04-29 : 06:59:46
hi all,
i want to combine 2 column to 1 with comma,
how to remove the comma if the second column is empty or null.
	select col1 + ', ' + col2  as a  from table

jleitao
Posting Yak Master

100 Posts

Posted - 2015-04-29 : 07:37:14
Select col1 + CASE WHEN col2 IS NULL THEN '' ELSE ', ' + Col2 END as A from table

------------------------
PS - Sorry my bad english
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2015-04-29 : 07:38:29
select coalesce(col1,'') + case when col2 is null then '' else ', ' end + coalesce(col2,'')

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -