在SqlServer中可以使用 for xml path方法将同一表的多行数据合并成一行。
select stuff((select ',' + rtrim(ltrim(字段))
from 表 where 条件 for xml path('')),1,1,'') as 别名
例如:
select stuff((select ',' + rtrim(ltrim(employee_id))
from employee_info where employee_id <='100' for xml path('')),1,1,'') as detail
运行后的效果:
001,003,007,014,0143,021,036,049,062,064,065,067,071,088
1507

被折叠的 条评论
为什么被折叠?



