Skip to content

Instantly share code, notes, and snippets.

@rnique
Created August 7, 2015 19:24
Show Gist options
  • Save rnique/ef34d1dcf36e20fefd55 to your computer and use it in GitHub Desktop.
Save rnique/ef34d1dcf36e20fefd55 to your computer and use it in GitHub Desktop.
Tight Equality / Inequality test taking into account possible NULL values (T-SQL).
-- 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