Very Fast String Unsplitter (CSV String Creator)
SQL Server 2000: Tested
SQL Server 2005: Tested
SQL Server 2008: Tested
SQL Server 2008R2: Tested
SQL Server 2012: Not Tested
Date: 5 Jun 2012
This is the reverse of the String Splitter but has no variable delimiter and creates a comma separated values (CSV) string.
The code utilises the COALESCE function to ensure that the last addition to the string has no trailing comma, thus removing the need to strip it off
The actual technique is a one-liner, and most of the code below is used to set up and execute test data.
This technique can be used in-line, in CTEs and subqueries