If the values are in one column and several rows, use something like followingdeclare @test table ([option] varchar(2))
insert @test
select 'A' union all
select 'B' union all
select 'A' union all
select 'C' union all
select 'D' union all
select 'B'
declare @concat varchar(8000)
select @concat = isnull(@concat + ',', '') + z.[option]
from (
select distinct top 100 percent [option]
from @test
order by [option]
) z
select @concat as Result
If you have one row and all values are in one column, start withdeclare @test table ([option] varchar(2))
insert @test
select distinct param
from fnSplit('A,B,A,C,D,B')
declare @concat varchar(8000)
select @concat = isnull(@concat + ',', '') + z.[option]
from (
select top 100 percent [option]
from @test
order by [option]
) z
select @concat as Result
Peter Larsson
Helsingborg, Sweden