考虑这个非常短的 T-SQL 代码,它使用案例对可为空的列进行测试
declare @t table(data varchar(10) null)
insert into @t values('something')
insert into @t values(null)
select data,
case data when null
then 'missing'
else 'not missing'
end as test
from @t
我得到的输出是:
data test
--------- -----------
something not missing
NULL not missing
然而我所期待的是
data test
--------- -----------
something not missing
NULL missing
关于这个可为空值的测试,我缺少什么
最佳答案
你想放这样的东西:
select data,
case when data is null
then 'missing'
else 'not missing'
end as test from @t
关于sql-server - null 未按预期工作的情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6928681/