SQL 合并多列为一行字符串

 

select PackID,stuff((select '\r\n'+rtrim(IDNum) 
                 from IndicatorPackIDNum 
                 where PackID=a.PackID for xml path('')
                ),1,4,'') as IDNums
from (select distinct PackID from IndicatorPackIDNum) a
 
原数据
 
合并后数据

posted @ 2011-11-09 15:32  无法更新的~  阅读(342)  评论(0编辑  收藏  举报