• my best guess is this will perform better, but it depends on the data;

    also it looks like you are pulling from a view(v_MOTS_RELATED_CONTACT_DATA_N), which itself could be pulling in a lot of unused data/columns that might not be needed

    myCTE is a placeholder for your real table name, and you might need to tweak the column names, as I removed any whitespace:

    /*--Results

    ServerNameMOTSEntries

    Server Acat

    Server Bcat

    Server Ccat,dog,mouse

    */

    With MyCTE (ServerName,MOTSEntry)

    AS

    (

    SELECT 'Server A','cat' UNION ALL

    SELECT 'Server B','cat' UNION ALL

    SELECT 'Server C','cat' UNION ALL

    SELECT 'Server C','dog' UNION ALL

    SELECT 'Server C','mouse'

    )

    SELECT ServerName,stuff(( SELECT ',' + MOTSEntry

    FROM MyCTE s2

    WHERE s2.ServerName= s1.ServerName --- must match GROUP BY below

    ORDER BY MOTSEntry

    FOR XML PATH('')

    ),1,1,'') as [MOTSEntries]

    FROM MyCTE s1

    GROUP BY s1.ServerName --- without GROUP BY multiple rows are returned

    ORDER BY s1.ServerName

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!