MSSQL stuff 函数的使用

将表中列的内容横向输出:

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

MSSQL stuff 函数的使用

 

上一篇:mssql for xml path使用


下一篇:MSSQL_变更定序(数据库、数据行)