处理分类拼接字段值的解法
以下是变量的方法解决分类拼接字段值
delcare @s varchar(8000),@i int
create table #t(id int, s varchar(100))
insert #t select 1,'a' union select 1,'b' union 2,'a'
select * into #t0 from #t order by id
set @s=''
set @i=-1
update #t0 set @s=case when @i=id then @s+','+s else s end, @i=id,id=@i,s=@s
select id,max(s) from #t0 grpup by id
drop table #t,#t0
显示的结果是:
id s
1 a,b
2 a
请问用自定义函数方法实现在上面同样的功能应该怎么写??