--测试数据
create table csdn(id int,txt varchar(10))
insert csdn
select 1, 'a ' union all
select 1, 'b ' union all
select 1, 'c ' union all
select 2, 'aa ' union all
select 2, 'bb ' union all
select 2, 'cc ' union all
select 3, 'aaa ' union all
select 3, 'bbb '
select * from csdn
go
create function Gettxt(@id int)
returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s= ' '
select @s=@s + ', ' +txt from csdn where id=@id
--return @s
return stuff(@s,1,1, ' ')
end
go
select id,dbo.Gettxt(id) txt from csdn group by id
go
drop function Gettxt
drop table csdn
go
贴子来源飞诺网( http://bbs.firnow.com) 详细出处参考: http://bbs.firnow.com/dview6t82595.html
create table csdn(id int,txt varchar(10))
insert csdn
select 1, 'a ' union all
select 1, 'b ' union all
select 1, 'c ' union all
select 2, 'aa ' union all
select 2, 'bb ' union all
select 2, 'cc ' union all
select 3, 'aaa ' union all
select 3, 'bbb '
select * from csdn
go
create function Gettxt(@id int)
returns varchar(8000)
as
begin
declare @s varchar(8000)
set @s= ' '
select @s=@s + ', ' +txt from csdn where id=@id
--return @s
return stuff(@s,1,1, ' ')
end
go
select id,dbo.Gettxt(id) txt from csdn group by id
go
drop function Gettxt
drop table csdn
go
贴子来源飞诺网( http://bbs.firnow.com) 详细出处参考: http://bbs.firnow.com/dview6t82595.html