读书人

一个列转为行的有关问题

发布时间: 2012-10-20 14:12:48 作者: rapoo

一个列转为行的问题
deptid bblistid

1 zc01
1 zc02
1 zc03
2 xx01
2 xx02
2 xx03
要求结果
deptid bblistid
1 zc01,zc02,zc03
2 xx01,xx02,xx03

[解决办法]
select deptid,
bblistid=stuff((select ','+bblistid from tb where deptid=a.deptid for xml path('')),1,1,'')
from tb a group by deptid
[解决办法]

探讨

SQL2000如何实现?

读书人网 >SQL Server

热点推荐