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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:45:38+00:00 2026-05-11T13:45:38+00:00

I was writing a Stored procedure today, and I ran into a problem where

  • 0

I was writing a Stored procedure today, and I ran into a problem where if one of the values is null (whether it be from a SELECT statement or whether it be a passed in parameter) my expression would evaluate to false where it ought to evaluate to true.

SET ANSI_NULLS ON; DECLARE @1 INT; DECLARE @2 INT; DECLARE @3 INT; DECLARE @4 INT;  SET @1 = 1; SET @2 = NULL; SET @3 = 3; SET @4 = 3;  IF ((@1 <> @2) OR (@3 <> @4))    BEGIN      SELECT 1;    END ELSE    BEGIN      SELECT 2;    END SELECT @1, @2, @3, @4 

Returns:

2  1, NULL, 3, 3 

I expected it to return:

1  1, NULL, 3, 3 

I know I’m missing something simple, anybody have any idea what it is?

Related Question

SQL: Why are NULL Values filtered Out within this WHERE clause?

  • 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. 2026-05-11T13:45:39+00:00Added an answer on May 11, 2026 at 1:45 pm

    One way of dealing with this is you can wrap your NULL values in a known unexpected value, i.e. -1:

    IF ((ISNULL(@1, -1) <> ISNULL(@2, -1)) OR (ISNULL(@3, -1) <> ISNULL(@4, -1)))    BEGIN      SELECT 1;    END ELSE    BEGIN      SELECT 2;    END 

    Obviously if -1 was a possibility then use a different number. If there is no non-possible value, then you will have to use CASE statements.

    A concise way of assigning NULL values to a ‘safe’ value follows:

    SET @1 = ISNULL(@1, -1)

    This allows the contional test code to remain ‘clutter-free’.

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

Sidebar

Related Questions

I'm writing a stored procedure. I know how to pass values from select into
I'm into writing a stored procedure which explodes a passed string by a passed
I am writing a stored procedure that works with a heavy select statement. The
I am writing a stored procedure that will get results from one table then
I'm writing a stored procedure to copy data from one user's table to another
I'm writing one stored procedure, which I have to create a xml column from
I am writing one stored procedure, i need to pass start and end date
i am writing stored procedures in MySQL that return values; CREATE PROCEDURE getCustomerById (id
I'm writing a stored procedure that should sync a table from our production environment
I'm writing a stored procedure on SQL Server 2000. I've written a complicated select

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.