Wednesday, 2 June 2021

SQL | Snowflake | IFNULL vs NULLIF function


 DIFFERENCE BETWEEN IFNULL AND NULLIF FUNCTION


These SQL functions are compatible with mysql, SQL Server, Power BI, Big query.


IFNULL FUNCTION: If the in-parameter is NULL then it returns the default out-parameter.


Syntax : IFNULL (<in-parameter>,<out-parameter>)

SQL Snowflake IFNULL( ) function
SQL Snowflake IFNULL( ) function


NULLIF FUNCTION: If the first in-parameter is equal/same to the second in-parameter it returns NULL. If the first in-parameter is not equal/same to the second in-parameter it returns the first in-parameter.

Syntax : NULLIF (<in-parameter-1>,<in-parameter-2>)

SQLSnowflake NULLIF ( ) function
SQLSnowflake NULLIF ( ) function


IFNULL( ) VS NULLIF( ) FUNCTION:


Features

IFNULL

NULLIF

Syntax

IFNULL (<in-parameter>,
<out-parameter>)

NULLIF (<in-parameter-1>,
<in-parameter-2>)

Example

[1] IFNULL(NULL,28)

[2] IFNULL(100, 28)

[1] NULLIF(28,28)
[2] NULLIF(100,28)

Number of
IN parameter

1

2

Number of
OUT parameter

1

0

If IN parameter is NULL

Returns out-parameter value
O/p : [1] Returns 28

NA

If IN parameter is NOT NULL

Returns in-parameter value
O/p : [2] Returns 100

NA

If IN parameter 1 is same/equal to IN parameter 2

NA

Returns NULL
O/p :[1] Returns NULL

If IN parameter 1 is not same/equal to IN parameter 2

NA

Returns in-parameter-1
O/p :[2] Returns 100


SQL Snowflake NULLIF vs IFNULL function
SQL Snowflake NULLIF vs IFNULL function


Read More :

No comments:

Post a Comment