列相等与不等

declare @f1 int, @v1 int
set @f1=null
set @v1=null
if @f1=@v1 or (@f1 is null and @v1 is null) print '相同' else print '不同'
if @f1<>@v1 or (@f1 is null and @v1 is not null) or (@f1 is not null and @v1 is null)
 print '不同' else print '相同'

print '------------------------------------------'
set @f1=1
set @v1=1
if @f1=@v1 or (@f1 is null and @v1 is null) print '相同' else print '不同'
if @f1<>@v1 or (@f1 is null and @v1 is not null) or (@f1 is not null and @v1 is null)
 print '不同' else print '相同'

print '------------------------------------------' 
set @f1=1
set @v1=null
if @f1=@v1 or (@f1 is null and @v1 is null) print '相同' else print '不同'
if @f1<>@v1 or (@f1 is null and @v1 is not null) or (@f1 is not null and @v1 is null)
 print '不同' else print '相同'

print '------------------------------------------'
set @f1=null
set @v1=1
if @f1=@v1 or (@f1 is null and @v1 is null) print '相同' else print '不同'
if @f1<>@v1 or (@f1 is null and @v1 is not null) or (@f1 is not null and @v1 is null)
 print '不同' else print '相同'

print '------------------------------------------'
set @f1=0
set @v1=1
if @f1=@v1 or (@f1 is null and @v1 is null) print '相同' else print '不同'
if @f1<>@v1 or (@f1 is null and @v1 is not null) or (@f1 is not null and @v1 is null)
 print '不同' else print '相同'

print '------------------------------------------' 

解决由于Null致使逻辑运算产生的误差

你可能感兴趣的:(列)