2016-07-29 48 views

回答

0
CREATE TABLE #A 
(ID INT, NAME VARCHAR(10)) 
INSERT INTO #A VALUES 
(1,'ANN'), 
(2,'JAKE'), 
(1,'JULIE'), 
(3,'PAUL'), 
(2,'SHANE'), 
(4,'KUMI') 

SELECT DISTINCT ID , 
STUFF((SELECT ','+NAME 
FROM #A T1 
WHERE T1.ID=T2.ID 
FOR XML PATH('')),1,1,'') FROM #A T2 
0

STUFF沒有做串聯,其對XML這確實this.Stuff只替換值按選擇

select id, 
stuff((select ','+name from #t1 t2 where t1.id=t2.id for xml path('')),1,1,'') 
from #t1 t1 
group by id 
相關問題