Monday, October 19, 2009

Aggregation with String in SQL Server

The following code will do the similar functionality of a amount column summation for String data (String concatenation)

SELECT DISTINCT Author, Titles
FROM (select Title, Author from BookStore) a
CROSS APPLY ( SELECT Title + ' '
FROM (select Title, Author from BookStore) b
WHERE a.Author = b.Author
ORDER BY Author
FOR XML PATH('') ) D ( Titles )

No comments: