使用位数据类型列查询Sql Server 2005

时间:2014-05-30 17:48:53

标签: sql-server tsql sql-server-2005

这不适用于sql server 2005

select * from [mytablename] where [mybitcolumn] <> 1

我必须使用......

select * from [mytablename] where (([mybitcolumn] is null) or ([mybitcolumn]=0))

是否有替代语法可以获得mybitcolum&lt;&gt;的行1?

2 个答案:

答案 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'