有点怪。我有一个CTE,它选择3列。和id,然后是两个varchar字段。 varchar字段使用CLR函数将名称连接在一起,并以'/'分隔它们。
我在5个环境上运行此查询,并在其中4个环境上返回带有'/'的名称。在另一个环境中,它是空字符串(所有环境/服务器都具有相同的db副本)。
运行CTE主体可以在所有环境下正常返回数据。
在注释掉sql的各个部分时,直到我加入5个以上的表(即使该表与查询无关)之前,也可以很好地返回数据。似乎无论我连接到哪个表,5次连接后,我的varchar数据都变为空字符串。如果我过滤出特定的ID,则会很好地返回数据。
我猜测一种环境配置与另一种环境相比有所不同。有人知道吗?
with my_cte as
(
select my_id,
dbo.List(names1, '/') names1,
dbo.List(names2, '/') names2
from table
where blah= blah
)
select A.some_field,
OU.names1,
OU.names2
from myTable A
inner join my_cte OU on (OU.this_id = A.this_id)
inner join table3
inner join table4
inner join table5
inner join table6 --once i get here, no matter what table6 is, the names1, names2 become empty string
where A.blah = xxxx;
快速解决方案是将CTE重写到临时表中,直到dba检查两个框之间的配置差异。感谢您的评论。