:::: MENU ::::

Comparing nulls

  • Nov 29 / 2008
  • 0
dbDigger, Null Values, T-SQL Interview Questions

Comparing nulls

Question:
What is the Output of the following

IF(NULL IN (34, 35, NULL))
PRINT 'TRUE'
IF(34 NOT IN (35, 36, NULL))
PRINT 'FALSE'

Answer:
Command(s) completed successfully.

Explanation:
Since NULL is an unknown entity, the result of comparing two unknowns is always false. This means that the PRINT statements are never executed as the result of the IF statement is always false.
Ref: IF..ELSE – http://msdn.microsoft.com/en-us/library/ms182717.aspx

Note: The Question is taken from SQLServercentral.com.

Consult us to explore the Databases. Contact us