">

SQL Server FOR XML PATH Generator

Generate T-SQL queries using FOR XML PATH('') and STUFF() for row-to-comma string concatenation, XML unescaping, and hierarchical XML generation.

Query Parameters
Generated T-SQL Query T-SQL Compliant

The Standard SQL Server String Aggregation Solution

Prior to SQL Server 2017, Microsoft SQL Server lacked a native GROUP_CONCAT() function like MySQL or STRING_AGG() like PostgreSQL. Developers worldwide relied on FOR XML PATH('') combined with STUFF() to concatenate multiple row values into a single delimited string.

Anatomy of the STUFF + FOR XML PATH Query

Frequently Asked Questions

When should I use STRING_AGG() instead?
If you are running SQL Server 2017 or later (or Azure SQL Database), STRING_AGG(ColumnName, ', ') is cleaner and faster. For backwards compatibility with SQL Server 2008–2016, FOR XML PATH('') is mandatory.