使用变量的字符串聚合

String aggregate using a variable

是否可以使用变量连接多行中的值(作为隐式聚合函数)?它在我的机器上似乎工作正常,但我没有看到推荐它。

declare @v_str varchar(4000) = ''
select top 5 @v_str = @v_str + ',' + city_name from city_table order by city_name
print @v_str

来自nvarchar concatenation / index / nvarchar(max) inexplicable behavior "The correct behavior for an aggregate concatenation query is undefined."