日期:2014-05-17 浏览次数:20705 次
create table #T(name nvarchar(30))
insert into #T
select '安神补脑液' union all
select '四件套' union all
select '山菇菌'
select distinct STUFF((select ','+name from #t for xml path('')),1,1,'') as name
from #T
/*
name
安神补脑液,四件套,山菇菌
*/
create table #T(name nvarchar(30))
insert into #T
select '安神补脑液' union all
select '四件套' union all
select '山菇菌'
select DISTINCT
stuff((select ','+name from #T b
ORDER BY GETDATE()
for xml path('')),1,1,'') 'name'
from #T a
/*
name
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
安神补脑液,四件套,山菇菌
*/