Created
August 7, 2015 19:24
-
-
Save rnique/ef34d1dcf36e20fefd55 to your computer and use it in GitHub Desktop.
Tight Equality / Inequality test taking into account possible NULL values (T-SQL).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- As suggested in Stackoverflow | |
-- http://stackoverflow.com/questions/1075142/how-to-compare-values-which-may-both-be-null-is-t-sql | |
-- | |
-- Equality (true if A & B have same value or both are null): | |
A = B OR ISNULL(A, B) IS NULL | |
-- OR | |
ISNULL(NULLIF(A, B), NULLIF(B, A)) IS NULL | |
-- Inequaltiy (true if A & B are different and contain null): | |
ISNULL(NULLIF(A, B), NULLIF(B, A)) IS NOT NULL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment