aku1 发表于 2008-5-9 16:04:59 |
use test create table t_example(id int identity(1,1) not null, meetingid varchar(10),Joiner varchar(10))
Insert t_example select '1000','李梅'
union all select '1000','王俊' union all select '1000','张风'
union all select '1001','王浩'
union all select '1001','刘涛'
Create function fn_merge(@id int) returns varchar(8000) as begin declare @r varchar(8000) set @r='' select @r=@r+','+Joiner from t_example where meetingid=@id return stuff(@r,1,1,'') end
go select meetingid, dbo.fn_Merge(meetingid) as joiner from t_example group by meetingid go
drop function fn_Merge
drop table t_example
|