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 2005 Forums
 Transact-SQL (2005)
 CONCAT Query

Author  Topic 

sureshprpt
Starting Member

33 Posts

Posted - 2014-06-24 : 01:04:39
Hi All,
I need one sql query to merge two columns , at the time of merging i need to insert "." between the two columns.

if my second column is blank , the "." not needed in the output.

The example mentioned below for your ready referce

Col1 Col2 - Otuput Needed
1100 IICI 1100.IICI
1100 IBSI 1100.IBSI
1200 1200
1300 1300
1400 SCIB 1400.SCIB

Thanks

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-06-24 : 02:35:03
but the second column has values for all the rows,you want to concatenate only if there are character values in col2?

Javeed Ahmed
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-06-24 : 02:36:32
can you try this one
select case when col2!=null then col1+'.'+col2 else '' end as col3 from table1

Javeed Ahmed
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-06-24 : 04:17:13
SELECT Col1, Col2, LTRIM(ISNULL(Col1, '') + ISNULL(' ' + Col2, ''))


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -