create function f_str(@col varchar(10))
returns varchar(8000)
as
begin
declare @str varchar(8000)
set @str=''
select @str=@str+','+col2 form 表 where col1=@col
return stuff(@str,1,1,'')
end
go
--查询
select col1
,dbo.f_str(col1) as 'col2'
from 表
group by col1