gotchasqlMinor
What's the difference between equality (=) and inequality (<>) on BIT field in SQL Server?
Viewed 0 times
fieldtheequalitybitwhatserversqldifferencebetweenand
Problem
Is there difference between
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?
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?
Solution
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.
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.
Context
StackExchange Database Administrators Q#289942, answer score: 6
Revisions (0)
No revisions yet.