SQLServer 多行数据的一个字段内容合并成一个

select djid, pxId,
JgmData = (substring((select ',' + JgmData
from D_Gsp_HqJgm where DjId = a.DjId and PxId = a.PxId
for xml path('')),2,9999))
from (select distinct djId,pxId from D_Gsp_HqJgm ) a

for xml path:它就是将查询结果集以XML形式展现,有了它我们可以简化我们的查询语句实现一些以前可能需要借助函数活存储过程来完成的工作。

猜你喜欢

转载自www.cnblogs.com/ftian26977863/p/11815907.html