首页 > 代码库 > Concatenating Row Values in Transact-SQL

Concatenating Row Values in Transact-SQL

Copied from https://www.simple-talk.com/sql/t-sql-programming/concatenating-row-values-in-transact-sql/

 

SELECT DISTINCT CategoryId    ,ProductNamesFROM Northwind.dbo.Products p1CROSS APPLY (    SELECT ProductName + ,    FROM Northwind.dbo.Products p2    WHERE p2.CategoryId = p1.CategoryId    ORDER BY ProductName    FOR XML PATH(‘‘)    ) D(ProductNames);

 

Concatenating Row Values in Transact-SQL