组合同一字段数据的函数(SQL)

来源:互联网 发布:java电商开源 编辑:程序博客网 时间:2024/06/05 23:54

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

原创粉丝点击