create table test
(
t1 int ,
t2 nvarchar(50)
)
insert into test values(1,'a'),(1,'b'),(1,'c'),(2,'a'),(2,'a'),(3,'c')
用function 返回 1的 a;b;c;
------解决方案--------------------
create function getT(@id int)
returns nvarchar(50)
begin
declare @a nvarchar(50)
select @a=''
select @a=@a+t2+';' from test where t1=@id
return @a
end
select dbo.getT(1)