在SQL Server中,如果 nullParam=NULL
在where子句中,它总是计算为false.这是违反直觉的,并且给我带来了许多错误.我确实理解IS NULL
和IS NOT NULL
关键字是正确的方法.但是为什么SQL服务器会以这种方式运行?
考虑以下代码 - 有人可以向我解释为什么一个查询不会抛出错误?我可以理解为什么它没有返回记录,但是它想要做什么?请记住,colA是一个int.它在2000,2005和2008 r2上的工作原理相同
create table #foo
( colA int )
insert into #foo
(colA)
values
(null)
select * from #foo --returns the one record we just created
select * from #foo where colA = null --does not throw an error and does not return a record! why??
select * from #foo where colA is null --returns the record
drop table #foo
Run Code Online (Sandbox Code Playgroud)
这个表中是否存在可以返回colA = null的记录?
我目前没有任何其他数据库供我试用 - 这是标准还是特定于MSSQL的行为?
我解雇了一个查询
SELECT * FROM tblEmp WHERE emp_id = 9737 AND mgr_id = NULL
Run Code Online (Sandbox Code Playgroud)
它没有回报任何价值.直到昨天它才这样做.什么可能改变?我们很多人在同一台服务器上工作,所以有可能有人改变了一些东西.
为了获得结果,我必须解雇
SELECT * FROM tblEmp WHERE emp_id = 9737 AND mgr_id IS NULL
Run Code Online (Sandbox Code Playgroud)
这是给出适当的输出.
由于我正在使用此查询,.Net
我担心如果设置重置为上一个时它会中断.会吗?