Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7638881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:16:51+00:00 2026-05-31T08:16:51+00:00

I don’t get the simple boolean algebra on my sql-server. According to msdn, the

  • 0

I don’t get the simple boolean algebra on my sql-server. According to msdn, the following statement should return “1”, but on my server it returns “0”.
Can you help me?

SET ANSI_NULLS ON
SELECT CASE WHEN NOT(1=NULL) THEN 1 ELSE 0 END

Please have a look at msdn. There it clearly states: “Comparing NULL to a non-NULL value always results in FALSE.” – no matter what the ANSI_NULLS-setting is. Thus “1=NULL” should be FALSE and NOT(FALSE) should thus be TRUE and the statement should return “1”.

But on my machine, it returns “0”!

One explanation might be, that “1=NULL” evaluates to “UNKNOWN”. NOT(UNKNOWN) is still UNKNOWN (msdn), which would force the CASE-Statement into the ELSE.

But then the official documentation of the equals-operator would be wrong. I cannot believe this!

Can anybody explain this behaviour?

Thank you very much for any help!

Edit (2012-03-15):

One thing I just found that might be of interest for some of you:

CREATE TABLE #FooTest (Value INT)
ALTER TABLE #FooTest WITH CHECK ADD CONSTRAINT ccFooTestValue CHECK (Value>1)
PRINT '(NULL>1) = ' + CASE WHEN NULL>1 THEN 'True' ELSE 'False' END
INSERT INTO #FooTest (Value) VALUES (NULL)

The print-Statement writes ‘False’, but the insertion runs without error.
SQL-Server seems to negate the check-constraint in order to search for rows that do not fulfill the constraint-check:

IF EXISTS (SELECT * FROM inserted WHERE NOT(Value>NULL)) <Generate error>

Since the check-constraint evaluates to UNKNOWN, the negation is also UNKNOWN and SqlServer does not find any row violating the check-constraint.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:16:52+00:00Added an answer on May 31, 2026 at 8:16 am

    The MSDN page for Equals that you link to definitely appears incorrect.

    Check the MSDN page for SET ANSI_NULLS.

    When SET ANSI_NULLS is ON, all comparisons against a null value
    evaluate to UNKNOWN.

    To get that example SQL statement to work as expected, you should use compare using “IS NULL” or “IS NOT NULL” instead of using the equals operator (=). For example:

    SELECT CASE WHEN NOT(1 IS NULL) THEN 1 ELSE 0 END

    OR

    SELECT CASE WHEN (1 IS NOT NULL) THEN 1 ELSE 0 END

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't ask me how but I managed to get accidentally the following remote branches
Don't really know how to formulate the title, but it should be pretty obvious
Don't know how to explain it better but i'm trying to get a response
Don't get me wrong, I want them to get saved. But I always thought
Don't get me wrong - I love Smalltalk, but... To me, the Squeak interface
Don't let below code scare you away . The question is really simple, only
Don't know how to google for such, but is there a way to query
I don't want PHP errors to display /html, but I want them to display
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.