Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to merge two rows into single row can any one help
Posted
Comments
Mario Majčica 18-Jul-12 8:13am    
Make an example. Your question is not clear. What kind of merge are you trying to do?

Hi ...

Please see the below example.

SQL
CREATE TABLE #Temp
(
[Numbers] varchar(40)
)
INSERT INTO #Temp VALUES('One');
INSERT INTO #Temp VALUES('Two');
INSERT INTO #Temp VALUES('Three');
INSERT INTO #Temp VALUES('Four');
INSERT INTO #Temp VALUES('Five');

select * from #Temp

DECLARE @str VARCHAR(100)
SELECT @str = COALESCE(@str + '', '') + [Numbers]
FROM #Temp
Print @str
 
Share this answer
 
Hi,

select col_name1 + '' + col_name2 from table_name
 
Share this answer
 
use Join
SQL
select tbl1.fld1 as t1_fld1,tbl1.fld2 as t1_fld2
,tbl2.fld1 as t2_fld1 ,tbl2.fld2 as t2_fld2
from
tbl1 
inner join tbl2 on tbl1.fld1=tbl2.fld1

tbl1
-------------
fld1   fld2
-------------
a      b
1      2  


tbl2
-------------
fld1   fld2
-------------
a      c
1      3


Result
---------------------------------------
t1_fld1   t1_fld2   t2_fld1   t2_fld2
---------------------------------------
a         b         a          c
1         2         1          3


two different tables rows are merged into single row using join

this way first & second tables' related rows will be shown as
single row in resultant table-set.

if you ask your question with example, then it will be more easy to understand.

Happy Coding!
:)
 
Share this answer
 
v2
SQL
UPDATE Table SET MergedColumn = Column1+' - '+Colum2
 
Share this answer
 
Comments
Ainy Mughal 15-Apr-14 6:24am    
this is to merger columns.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900