create function add_string(@id varchar(16))returns varchar(300) as begin declare @s nvarchar(300) set @s='' if((select count(序号) from table where 编号=@ID )>0) begin select @s=@s+','+名称 from pcddw where 项目编号=@ID set @s=stuff(@s,1,1,'') end return(@s) end 例如 ID VALUE 1 HFUT 1 USTC 组合后得到 HFUT, USTC