【发布时间】:2013-03-14 14:41:26
【问题描述】:
在 Adaptive Server Enterprise/15.0.3/EBF 17157 ESD#3/P/x86_64/Enterprise Linux/ase1503/2726/64-bit/FBO/ 上运行
下面的代码不应该输入子字符串大小写,但是我会看到一个 Sybase 错误 536。
这是一种优化形式,它评估所有路径而不考虑实际值??
我们可以解决这个问题,但想知道为什么?
declare @test float
declare @test1 char(10)
create table #TestTable
(
Dno int,
Code varchar(10)
)
Insert into #TestTable values (1,'code')
set @test1 = 'ddd'
print 'test'
select @test = case
when (1=1) then 2
when (1=0) then (select Dno FROM #TestTable WHERE Code = substring('abc',1,charindex(@test1,'a')-1) AND Dno = 1)
else 10
end
select @test
drop table #TestTable
【问题讨论】:
-
更新:似乎只有在 case 语句中存在子查询时才会出错....仍然不知道为什么它选择在这种情况下显然不会命中代码路径时进行评估。
-
请检查答案并推进问题