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 3233530
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:17:15+00:00 2026-05-17T17:17:15+00:00

So I have a simple query that returns a listing of products SELECT Model,

  • 0

So I have a simple query that returns a listing of products

SELECT     Model, CategoryID
FROM         Products
WHERE     (Model = '010-00749-01') 

This returns

010-00749-01    00000000-0000-0000-0000-000000000000
010-00749-01    NULL

Which is correct, so I wanted only the products whose CategoryID is not ‘00000000-0000-0000-0000-000000000000’ so I have

SELECT     Model, CategoryID
FROM         Products
WHERE     (Model = '010-00749-01') 
AND (CategoryID <> '00000000-0000-0000-0000-000000000000') 

But this returns no result. So I changed the query to

SELECT     Model, CategoryID
FROM         Products
WHERE     (Model = '010-00749-01') 
AND ((CategoryID <> '00000000-0000-0000-0000-000000000000') OR  (CategoryID  IS NULL))

Which returns expected result

010-00749-01    NULL

Can someone explain this behavior to me?
MS SQL Server 2008

  • 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-17T17:17:15+00:00Added an answer on May 17, 2026 at 5:17 pm

    Check out the full reference on Books Online – by default ANSI_NULLS is on meaning you’d need to use the approach you have done. Otherwise, you could switch that setting OFF at the start of the query to switch the behaviour round.

    When SET ANSI_NULLS is ON, a SELECT
    statement that uses WHERE column_name
    = NULL returns zero rows even if there are null values in column_name. A
    SELECT statement that uses WHERE
    column_name <> NULL returns zero rows
    even if there are nonnull values in
    column_name.

    …

    When SET ANSI_NULLS
    is ON, all comparisons against a null
    value evaluate to UNKNOWN. When SET
    ANSI_NULLS is OFF, comparisons of all
    data against a null value evaluate to
    TRUE if the data value is NULL.

    Here’s a simple example to demonstrate the behaviour with regard to comparisons against NULL:

    -- This will print TRUE
    SET ANSI_NULLS OFF;
    IF NULL <> 'A'
        PRINT 'TRUE'
    ELSE
        PRINT 'FALSE'
    
    -- This will print FALSE
    SET ANSI_NULLS ON;
    IF NULL <> 'A'
        PRINT 'TRUE'
    ELSE
        PRINT 'FALSE'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple query like this: select * from mytable where id >
I have very simple query like this: SELECT * FROM `all_conversations` WHERE `deleted_1` !=
I have a simple SQL query (using SqlCommand, SqlTransaction) in .NET 2.0 that returns
Lets suppose that I have the following simple query var q = from p
I have a very simple query that only returns one record. When I try
I have a simple query which returns 25,026 rows: MySqlCommand cmd = new MySqlCommand(SELECT
I have a very simple query that's giving me unexpected results. Hints on where
I have a simple Nhibernate Linq query that is returning more results than expected:
I have a simple query: $query = new WP_Query('showposts=5'); that will obviously display 5
I have a simple SQL query in PostgreSQL 8.3 that grabs a bunch of

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.