日期:2014-05-17 浏览次数:20504 次
CREATE TABLE #temp(QID VARCHAR(10),QTITLE VARCHAR(10), TYPE INT, ANSWER VARCHAR(10))
INSERT #temp
select ' Q1', 'AAAA', ' 3', 'aaaa' union all
select ' Q2', 'BBBB', ' 5', 'bbbb' union all
select ' Q3', 'CCCC', ' 6', 'cccc' union all
select ' Q3', 'CCCC', ' 6', 'dddd' union all
select ' Q4', 'EEEE', ' 7', 'eeee' union all
select ' Q4', 'EEEE', ' 7', 'ffff' union all
select ' Q5', 'GGGG', ' 3', 'gggg'
SELECT QID, Qtitle, [Type],
anser = STUFF(((SELECT '、'+answer FROM #temp b WHERE a.qid = b.qid FOR XML PATH(''))),1,1,'')
FROM #temp a
GROUP BY QID, Qtitle, Type
/*
QID Qtitle Type anser
Q1 AAAA 3 aaaa
Q2 BBBB 5 bbbb
Q3 CCCC 6 cccc、dddd
Q4 EEEE 7 eeee、ffff
Q5 GGGG 3 gggg
*/