这不适用于sql server 2005
select * from [mytablename] where [mybitcolumn] <> 1
我必须使用......
select * from [mytablename] where (([mybitcolumn] is null) or ([mybitcolumn]=0))
是否有替代语法可以获得mybitcolum&lt;&gt;的行1?
答案 0 :(得分:1)
你可以这样做:
select * from [mytablename] where isnull([mybitcolumn], 0) = 0
虽然它只是稍微好一点。
或者,我犹豫不决,你关闭ANSI NULLS
。例如:
set ansi_nulls on
go
if (1 != null)
print 'This will not print equal because NULL is a third boolean value.'
set ansi_nulls off
go
if (1 != null)
print 'Not equal since we told SQL Server to treat null as any other value'
另请查看Three-valued logic。
答案 1 :(得分:1)
由于1
被视为true
;使用where [mybitcolumn] <> 1
,您尝试获取false
方案。如果你尝试下面怎么办
select * from [mytablename] where [mybitcolumn] = 'false'
如果mybitcolumn
包含NULL
,则您可以使用ISNULL
功能
select * from [mytablename] where ISNULL([mybitcolumn],0) = 'false'