for xml path()以xml形式展现
select ‘|’+Name from table for xml path('')
stuff(param1,startIndex,length,param2)
将param1中的startIndex开始,删除length字符串,用param2代替
//去掉第一个 ‘|’
SELECT DISTINCT Name,
STUFF((SELECT ',' + Name FROM table
WHERE Name = T.Name FOR XML PATH('')), 1,1, '') AS name2 FROM table AS T
网友评论