• Home
  • About
  • Resume

T-SQL String Aggregate in SQL Server

By , 06/25/2009 3:00 PM

T-SQL dialect of SQL doesn’t have aggregate functions for strings, but there is an easy workaround using magic of XML.

Consider Employees table of the Northwind database. When I run following query:

SELECT Country, FirstName FROM Employees ORDER BY Country, FirstName

I get following result:

Country FirstName
UK      Anne
UK      Michael
UK      Robert
UK      Steven
USA     Andrew
USA     Janet
USA     Laura
USA     Margaret
USA     Nancy

Now I want to combine first names into comma separated strings grouped by country. Continue reading 'T-SQL String Aggregate in SQL Server'»

Panorama Theme by Themocracy