--原显示语句(纵)
select WrgNAME,WrgWXFLG,WrgWO from [DoerERP_E6].dbo.sc_Wrg where WrgWXFLG=1 AND WrgWO='SC001357' order by WrgNO ;
--SQL字段接拼之后语句(横)
SELECT WrgWO ,
STUFF((SELECT ',' + WrgNAME FROM [DoerERP_E6].dbo.sc_Wrg AS e WHERE e.WrgWO = t.WrgWO AND e.WrgWXFLG=1 ORDER BY e.WrgNO FOR XML PATH('')) ,1,1,'') AS '应外发工序/艺'
FROM [DoerERP_E6].dbo.sc_Wrg AS t WHERE t.WrgWXFLG=1 and t.WrgWO='SC001357' GROUP BY t.WrgWO;