Solved

Testing if bit field = 1

Posted on 2004-04-26
5
354 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 50 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Call to SQL server times out 5 55
SQL syntax for max(date) 3 37
SQL: Transformation or Pivot 3 34
Total count in section based report in SSRS 10 8
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

734 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