摘要:
最近开发项目用到一个需要行转列并且拼接列的语句,通过网上查找整理出来如下select ceid, SUBSTRING(names, 1, len(names)-1) from View_HearInfo AS A cross APPLY(SELECT Expr25 + ',' FROM View_HearInfo AS B WHERE A.ceid = B.ceid group by Expr25 FOR XML PATH('') ) D (names)where ceid = 2GROUP BY ceid, names主要用到cross apply 和for 阅读全文