创建一个合并处理函数
--创建一个合并处理函数
Create function f_str( @a varchar(30))
returns varchar(8000)
as
begin
declare @re varchar(8000)
set @re=''
select @re=@re+','+cast(a as varchar)
from tbl
where b=@a
return(stuff(@re,1,1,''))
end
go
--调用函数实现查询
select distinct b as a,b=dbo.f_str(b)
from tbl
group by b
go