create function fn_test(@a int) returns varchar(100) as begin declare @return varchar(100) select @return=isnull(@return)+rtrim(组成)+树种 from tablename where 编码=@a return (@return) end
select 编码,dbo.fn_test(编码) as 树种组成 from tablename group by 编码
create function fn_test(@a int) returns varchar(100) as begin declare @return varchar(100) select @return=isnull(@return)+rtrim(组成)+树种 from tablename where 编码=@a order by 组成 desc return (@return) end