海绵宝宝撒
值得一提的是,两者之间的类型处理也可以有所作为(请参阅此相关答案项(2))。假设查询尝试使用快捷方式编写空比较:select * from SomeTable where IsNull(SomeNullableBitField, -1) != IsNull(SomeOtherNullableBitField, -1);不同于select * from SomeTable where coalesce(SomeNullableBitField, -1) != coalesce(SomeOtherNullableBitField, -1);因为在第一种情况下,IsNull()强制类型为一点(因此将-1转换为true),而在第二种情况下,两者都会提升为int值。with input as ( select convert(bit, 1) as BitOn, convert(bit, 0) as BitOff, convert(bit, null) as BitNull)select BitOn, BitOff, BitNull, IsNull(BitOn, -1) IsNullBitOn, -- true IsNull(BitOff, -1) IsNullBitOff, -- false IsNull(BitNull, -1) IsNullBitNull, -- true, converts the -1 to bit coalesce(BitOn, -1) CoalesceBitOn, -- 1 coalesce(BitOff, -1) CoalesceBitOff, -- 0 coalesce(BitNull, -1) CoalesceBitNull -- -1 from input;问题本身也有类似的评论/链接(@Martin Smith)。