Hi @minh tran
Maybe you want to merge data from multiple column into one column ,right?
Here is an example,hope it helps
create table sourcetable
( id integer identity(1,1),
last_name varchar(20),
address varchar(50))
insert into sourcetable(last_name,address)
select 'joe','Main String, GA 30033'
union all
select 'John','North Avenue, Hapeville 30324'
union all
select 'John','North Druid Hill, Atlanta 30129'
select * from sourcetable
select CONCAT('name:',last_name,' ','address:',address) from sourcetable where last_name = 'John'
And if you want to merge all row values ,you can try this statement
DECLARE @CHARSTRING VARCHAR(MAX)
SET @CHARSTRING = ';WITH CTE AS(select CONTENT = CONCAT(''name:'',last_name,'' '',''address:'',address) from sourcetable where last_name = ''John'')
(SELECT STRING_AGG(CONTENT,''||'') AS SSS FROM CTE)'
EXEC (@CHARSTRING)
Best Regards,
Isabella
If the answer is the right solution, please click "Accept Answer" and upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.