将表中列的内容横向输出:
SELECT NOTENO,
WERKS = STUFF((SELECT ',' + WERKS FROM ALNOTE A WHERE A.NOTENO = F.NOTENO FOR XML PATH('')), 1 ,1 ,'') ,
TEAM = STUFF((SELECT ',' + TEAM FROM ALNOTE B WHERE B.NOTENO = F.NOTENO FOR XML PATH('')),1,1,''),
ZMCNO= STUFF((SELECT ',' + ZMCNO FROM ALNOTE C WHERE C.NOTENO = F.NOTENO FOR XML PATH('')),1,1,''),
OPCD = STUFF((SELECT ',' + OPCD FROM ALNOTE D WHERE D. NOTENO = F.NOTENO FOR XML PATH('')), 1,1, '')
FROM ALNOTE F
GROUP BY F.NOTENO