Monday, 10 February 2014

Difference Between IsNull() and Coalesce()

Both  IsNull() and Coalesce() are used for dealing with null values. And, they differ in following ways.

IsNull Function

  1. This is not a standard SQL function. i.e if you migrate from SQL Server to Some other RDBMS this function will not work.
  2. IsNull() function takes 2 arguments. Such that, if value of first argument is null then it is replaced with non null value from second argument.
  3. This function always replaces NULL with second argument, Hence Non NULL value is guaranteed.
  4. Syntax: IsNull(Col1,0)
Coalesce Function
  1. Coalesce() is standard SQL Function so porting is easy.
  2. It allows n number of argument and replaces null value in first argument with Value of first non null value argument from rest of the arguments.
  3. Non NULL value is not guaranteed. Because, if all arguments return Null value, Value return by Coalesce is also NULL.
  4. Coalesce(Col1, Col2, Col3,....,Coln)

No comments:

Post a Comment