select c.report_with_id,ri.entid,
stuff((select ';' + cast(row_number() over(order by t.uuid) as varchar) +'.'
+ cast(isnull(t.maincontent,'') as varchar) from sa_idx_checkspecial t
where t.report_with_id = c.report_with_id for xml path('')) , 1 , 1 , '') as zynr,
sum(c.question) as question,sum(c.suggestion) as suggestion,sum(c.consult) as consult,
sum(c.prompt) as prompt,sum(c.suggest) as suggest,sum(c.others) as others
from sa_report_instance ri,sa_idx_checkspecial c
where ri.uuid=c.report_with_id and ri.rep_period=1 and ri.rep_annual=2015
and ri.report_code='zd' and ri.report_type=1
group by c.report_with_id,ri.entid
查找
使用 SQL的 for xml path来进行字符串拼接
http://www.cnblogs.com/repository/archive/2011/01/18/1938418.html
查找
http://www.cnblogs.com/345563452/archive/2009/10/29/1592048.html