?
Solved

Testing if bit field = 1

Posted on 2004-04-26
5
Medium Priority
?
371 Views
Last Modified: 2012-08-13
I have a field 'del' in a table, 'mytable',  defined as type 'bit'. It is also nullable. I have two rows, one with del=1, and one with del=NULL. In my select statement I have


select * from mytable
where del<>1

but I am returned no rows. Can i test a bit field this way?

thx

Rich
0
Comment
Question by:RichardFox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:RichardFox
ID: 10919739
Oh, and if I use

select * from mytable
where del=1

the row is returned. So del=1 appears to work but del<>1 doesn't
0
 

Author Comment

by:RichardFox
ID: 10920020
And a little bit more (excuse the pun):

If a row has del set to zero,

select * from mytable
where del<>1

returns the row. BUT, it does not return rows where del is NULL! Why? Definitely NULL is <> 1!
0
 
LVL 34

Expert Comment

by:arbert
ID: 10920050
This is how null works--straight from books online:

Care must be taken when comparing null values. The behavior of the comparison depends on the setting of the SET ANSI_NULLS option.

When SET ANSI_NULLS is ON, a comparison in which one or more of the expressions is NULL does not yield either TRUE or FALSE; it yields UNKNOWN. This is because a value that is unknown cannot be compared logically against any other value. This occurs if either an expression is compared to the literal NULL, or if two expressions are compared and one of them evaluates to NULL. For example, this comparison always yields UNKNOWN when ANSI_NULLS is ON:
0
 
LVL 34

Accepted Solution

by:
arbert earned 200 total points
ID: 10920055

select * from mytable
where del<>1 or del is null
0
 

Author Comment

by:RichardFox
ID: 10920103
Thanks for the education, I appreciate it
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question