All we need is an easy explanation of the problem, so here it is.
Is there difference between WHERE [BitField] = 1
and WHERE [BitField] <> 0
?
They seem logically equivalent.
SQL Server, however, disagrees and creates slightly different execution plans. (Which is bad because the second form doesn’t use existing indexes very effectively.)
Am I missing something, or it is just the way inequality operators behave?
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
They seem logically equivalent.
They are. Even with ANSI_NULLS OFF "a SELECT statement that uses WHERE column_name <> XYZ_value returns all rows that are not XYZ_value and that are not NULL."
I found an old feedback item for this here, you can go vote for it.
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0