• That function looks pretty similar to the one from the original article, which I called "fn_Split". It does fine, too, and it will work on older versions of SQL Server.

    For joining, there are a couple of basic ways to do it. The tough part can be when you want to pass the table name involved as a variable, as you either you have to do some SQL-Server-2008-only stuff using a newly declared type, or you have to use string concatenation with EXEC, so be careful with that one regarding SQL Injection... AND some of the XML functionality might let you find a back door, too.

    The basic premise for joining can use either CTE (as I wrote in my very first blog post) or a COALESCE() or perhaps a CURSOR (which will be a little slow). Here is a quick and dirty example using a table variable and a 2008-only insert statement to fill that test table variable, and then a COALESCE() to join all the rows in that table:

    DECLARE @table TABLE (token VARCHAR(max));

    INSERT INTO @table VALUES ('xyz'),('pdq'),('abc'),('123')

    DECLARE @joined VARCHAR(max)

    SELECT @joined=COALESCE(@joined+',', '')+token FROM @table

    SELECT @joined