sql server字段合并逗号隔开

SELECT
COMBO,
PRD_GROUP,
  PRD_LINE,
  STUFF((
    SELECT ', ' + CAST([MPG] AS VARCHAR(MAX)) 
    FROM MDM.TB_AUTH_MPG
    WHERE PRD_LINE = Results.PRD_LINE AND PRD_GROUP = Results.PRD_GROUP AND COMBO = Results.COMBO
    FOR XML PATH(''),TYPE).value('(./text())[1]','VARCHAR(MAX)')
  ,1,2,'') AS REFERENCE
FROM MDM.TB_AUTH_MPG Results
GROUP BY COMBO, PRD_GROUP, PRD_LINE

http://www.cnblogs.com/zhangq723/archive/2011/10/10/2205304.html

http://zhidao.baidu.com/link?url=kCizANGUaISmJCtm_zZLq8S8zlw2HXmH3acgwP8FXLcRTqFLZxL10Kh_-EBFJzJ7h9qn7LyJM4NPAdDavgxP6_

posted @ 2016-01-20 10:46  刘竹青  阅读(250)  评论(0编辑  收藏  举报