• Luis Cazares (10/1/2014)


    You might be experiencing a problem described by Jeff Moden in the following article:

    http://www.sqlservercentral.com/articles/Performance+Tuning/62278/

    I'm not sure how you tried to do the update with XML PATH, but it might not be the cause of the problem.

    UPDATE t

    SET col2 = col2 + STUFF( (SELECT ',' + f.col4

    FROM @tbl_from f

    WHERE t.col1 = f.col3

    FOR XML PATH('')), 1, 1, '')

    FROM @tbl_to t

    Thanks for putting me on the right track, that article was extremely useful!

    One thing, I've added a 'where exists' to only update relevant results..

    UPDATE t

    SET col2 = col2 + STUFF( (SELECT ',' + f.col4

    FROM @tbl_from f

    WHERE t.col1 = f.col3

    FOR XML PATH('')), 1, 1, '')

    FROM @tbl_to t

    WHERE exists (SELECT 1 FROM @tbl_from f WHERE f.sessionid = t.sessionid)

    [/quote]