create table tb(id int, value varchar(10))
insert into tb values(1, 'aa')
insert into tb values(1, 'bb')
insert into tb values(2, 'aaa')
insert into tb values(2, 'bbb')
insert into tb values(2, 'ccc')
go
select * from tb
select id,
[value]= stuff((select ',' +[value] from tb t where id = tb.id for xml path('')),1,1, '')
from tb --和别的表关联的where条件
group by id
drop table tb
SELECT STUFF('abcdef',2,3, 'ijklmn') --aijklmnef