create function f_sumstr(@id varchar(10))
returns nvarchar(4000)
as 
begin
  declare @ret nvarchar(4000)
  set @ret = ''
  select @ret = @ret +' '+ col2 from tabname where col1 = @id
  return stuff(@ret,1,1,'')
end --执行
select col1,dbo.f_sumstr(col1) from tabname group by col1