sql 将查询结果为多行一列合并为一行一列

使用sql stuff函数

/*         stuff(param1, startIndex, length, param2)
说明:将param1中自startIndex(SQL中都是从1开始,而非0)起,删除length个字符,然后用param2替换删掉的字符。*/

示例:

select  po_no = stuff((select ';' + 字段 from 表 t where 查询条件 for xml path('')) , 1 , 1 , '') 

原文地址:https://www.cnblogs.com/hvaven/p/5915723.html