SQL多行数据合并为一行
这个是准备导出一个问卷的,可是发觉问题答案不在同一行,显示的时候就一直分行显示,如何合并到一行呢?
这个是我写的查询
SELECT DISTINCT questiontable.Title, questiontable.necessaryanswer, questiontype.topicName, optionstable.Scontent
FROM questiontable,optionstable,questiontype,questionnaire
where questiontable.questionID = optionstable.questionID and questiontable.topicID = questiontype.topicID and questiontable.papered=questionnaire.paperID
急求帮助!!!
把写好的查询语句贴我,附上说明,万分感谢
------解决方案--------------------
select distinct a.title,b.necessaryanswer,c.topicname,
(select scontent+',' from questionnaire where paperid = a.papered for xml path('')) as scontent
from questiontable a,optionstable b,questiontype c
where a.questionid = b.questionid
and a.topicid = b.topicid
试试!