create function show(@no varchar(4))
returns varchar(100)
as
begin
declare @back varchar(100)
set @back=''
select @back=@back+items+',' from tb where no=@no
return(left(@back,len(@back)-1))
end
select no from tb group by no
create table tb(no int,item varchar(10))
insert into tb
select '01', 'AA'
union all select '01', 'BB'
union all select'02', 'CC'
union all select'02', 'DD'
union all select'02', 'EE'
union all select'03', 'FF'
union all select'04', 'GG'
union all select'04', 'HH'
go
create function dbo.fc_str(@no varchar(100))
returns varchar(100)
as
begin
declare @sql varchar(1000)
set @sql=''
select @sql=@sql+','+cast(item as varchar(100)) from tb where no=@no
return stuff(@sql,1,1,'')
end
go
select no,dbo.fc_str(no) as item from tb group by no