• Hugo is 100% correct! Using this technique is 100% unpredictable. It will not work with table variables, derived tables, etc.

    If you need to make a delimited list of values use XML.

    Example:

    The following code will create a semi-colon delimited list of user names where "NAME" contains names in the format of "LastName, FirstName".

    SELECT STUFF(V.DELIMITED_LIST, 1, 2, N'')

    FROM

    (

    SELECT

    N'; ' + U.NAME AS "text()"

    FROM

    USERS U

    WHERE U.NAME IS NOT NULL -- exclude any NULL values

    AND U.NAME <> N'' -- exclude any zero-length strings

    ORDER BY 1

    FOR XML PATH(N'')

    ) AS V (DELIMITED_LIST)


    [font="Arial Narrow"](PHB) I think we should build an SQL database. (Dilbert) What color do you want that database? (PHB) I think mauve has the most RAM.[/font]