1将检索结果拼接成字符串
select stuff ( (select distinct ', ' + cast(key1 as varchar(20)) from (select 列名 as key1 from 表名 where 条件) a for xml path('') ), 1 , 1 , '' )
2 给检索结果加分隔符
select quotename(列名,’)’) from 表名
检索结果为 (列名)
‘)’可变更
1将检索结果拼接成字符串
select stuff ( (select distinct ', ' + cast(key1 as varchar(20)) from (select 列名 as key1 from 表名 where 条件) a for xml path('') ), 1 , 1 , '' )
2 给检索结果加分隔符
select quotename(列名,’)’) from 表名
检索结果为 (列名)
‘)’可变更