create table #test ( id int not null, memeo int not null ) insert into #test(id,memeo) values(1,100) insert into #test(id,memeo) values(2,200) insert into #test(id,memeo) values(3,300) SELECT STUFF((SELECT ','+cast(memeo as nvarchar(20)) FROM #test for xml path('')),1,1,'') drop table #test
总结:
格式:
SELECT STUFF((SELECT ','+字段 FROM 表名 for xml path('')),1,1,'')