SQL Server How to combined String rows to one column

ippsafx7  于 2023-08-02  发布在  其他
关注(0)|答案(1)|浏览(106)
data Adata B
appleapple, banana, cat
bananaapple, banana, cat
catapple, banana, cat
SELECT 
  data A,
  '' as data B
From tbl_test;

If I have data like Column data A and I want to combined this data to another column like data b

How can I query this one and show like I want

Sorry for my news sql

lb3vh1jj

lb3vh1jj1#

By using STUFF we can combine all column data into single column by writing Subquery it will give's Result to all columns suitable for SQL Server 2014 . Code is as follows.

select dataA,STUFF((
select ','+r.dataA
from TestTable as r
for xml path('')),1,1,'') as dataB From TestTable

相关问题