String aggregate using a variable

谁说我不能喝 提交于 2019-12-12 03:27:28

问题


Is is okay to use a variable to concatenate a value from several rows ( as an implicit aggregate function )? It seems to work fine on my machine, but I haven't seen it recommended.

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

回答1:


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



来源:https://stackoverflow.com/questions/44223465/string-aggregate-using-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!