if exists(select * from sysobjects where [name]='tb1')
drop table tb1
go
create table tb1
(
[name] varchar(20),
zm varchar(10)
)
go
insert into tb1([name],zm)
(
select '10060001','a' union
select '10060002','b' union
select '10060003','a' union
select '10060004','c' union
select '10060005','c' union
select '10060006','c'
)
go
select * from tb1
go
select zm,tutor_name= stuff((select ',' + [name]
from tb1 t where zm = tb1.zm for xml path('')) , 1 , 1 , '')
from tb1 group by zm
go
create function test(@temp varchar(10))
returns varchar(1000)
as
begin
declare @t varchar(1000)
set @t =''
select @t= @t+col1
from tb
where colb=@temp
return (@t)
end
select col2,count(col1),test(col2)
from tb
group by col2