Tuesday, June 28, 2011

What NULLIF () Do? How It Differs From ISNULL ()?


NULLIF () returns zero if the two specified expressions are equal in function.

Syntax

NULLIF (expression1, expression2)

If expression1 = expression2, the function returns NULL.

ISNULL () function replaces an expression with no specified value.

The syntax used is

ISNULL (expression1, expression2)

If expr1 is NULL, then the function returns expression2 output.

ISNULL functionality can be written using if ... WHEN the

CASE WHEN expression1 THEN END ELSE NULL Expression2 expression1

An example of these two functions are shown below

Select ISNULL (NULL, 'hello') as IsNullOutPut1

, IsNull (1001, 1) as IsNullOutPut2

, NULLIF (100, 100) that NullIfOutPut1

, NULLIF (1, 100) that NullIfOutPut2

No comments:

Post a Comment