gpt4 book ai didi

sql-server - TSQL Oddity 与 String_Agg

转载 作者:行者123 更新时间:2023-12-01 00:36:17 25 4
gpt4 key购买 nike

此查询返回第二个字符串 Agg 函数的错误结果:

select
string_agg(t.name, ';') as BBB,
string_agg(t.name, ', ' ) as CCC
from sys.tables as t

但是如果你改变 t.name 它会起作用,例如:

select
string_agg(t.name, ';') as BBB,
string_agg('' + t.name, ', ' ) as CCC
from sys.tables as t

知道为什么吗?这是错误吗?

最佳答案

有趣的是,这是一个错误,当然。它检查第一个参数并将其用作第二个参数的缓存。

它在 sys.* 对象上运行异常

但是查询在其他数据库表上运行成功。

我使用执行计划执行了确切的查询。

enter image description here

更有趣的是,当我在不同表的用户数据库上执行查询时,查询返回预期数据。

本例没有错误

enter image description here

关于sql-server - TSQL Oddity 与 String_Agg,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50753590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com