Wednesday, August 6, 2014

Explain with example ISNULL, NULLIF and COALESCE in SQL Server


ISNULL : Replaces NULL with the specified replacement value.

NULLIF : Returns a null value if the two specified expressions are equal.

COALESCE : Returns the first non-null argument.(msdn: Evaluates the arguments in order and returns the current value of the first expression that initially does not evaluate to NULL).

Here are the examples and it's results:

SELECT ISNULL(null,1)
--Result: 1

SELECT NULLIF(1,1)
--Result: NULL

SELECT COALESCE(1,null,null,null)
--Result: 1

SELECT COALESCE(null,2,3,4)
--Result: 2

SELECT COALESCE(null,null,3,4)
--Result: 3

SELECT COALESCE(null,null,null,4)
--Result: 4

SELECT ISNULL(NULLIF(COALESCE(null,null,null,4),4),1)
--Result: 1


1 comment:

  1. It is not my first time to pay a quick visit this site, i aam visiting thhis web age
    dailly and take nice information from here every day.

    ReplyDelete

React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to ...