declare @values nvarchar(max)
set @values = ''
select @values = @values + ',' + ColumnName
from
(select distinct
ColumnName --表字段
from TableName --表名
) t
select isnull(stuff(@values, 1, 1, ''),'')
declare @values nvarchar(max)
set @values = ''
select @values = @values + ',' + ColumnName
from
(select distinct
ColumnName --表字段
from TableName --表名
) t
select isnull(stuff(@values, 1, 1, ''),'')