+= in SELECT clause; constant vs column
It's in the wrong place in the documentation, so not surprising that you haven't found it:
Don't use a variable in a SELECT statement to concatenate values (that is, to compute aggregate values). Unexpected query results may occur. Because, all expressions in the SELECT list (including assignments) aren't necessarily run exactly once for each output row
It's better to look for different ways of doing string concatenation. If your version supports it, choose to use STRING_AGG
. For earlier versions, Aaron Bertrand has provided a good set of options (hat tip to Panagiotis Kanavos for providing the link)