使用变量进行字符串汇总 [英] String aggregate using a variable

查看:112
本文介绍了使用变量进行字符串汇总的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用一个变量来连接多个行中的值(作为隐式聚合函数)吗?

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


推荐答案

来自 nvarchar串联/索引/ nvarchar(最大值)莫名其妙的行为
未定义聚合级联查询的正确行为。

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

这篇关于使用变量进行字符串汇总的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆