Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is most correct - coalesce(sum(value)) OR sum(coalesce(value))?

Tags:

People also ask

Which is better coalesce or Isnull?

advantage that COALESCE has over ISNULL is that it supports more than two inputs, whereas ISNULL supports only two. Another advantage of COALESCE is that it's a standard function (namely, defined by the ISO/ANSI SQL standards), whereas ISNULL is T-SQL–specific.

Which is faster coalesce or Isnull?

Mladen aka spirit1 posted a speed test of COALESCE vs. ISNULL. Reported result: COALESCE is faster.

What is true about the coalesce function?

The COALESCE function returns the first non-NULL value from a series of expressions. The expressions are evaluated in the order in which they are specified, and the result of the function is the first value that is not null. The result of the COALESCE function returns NULL only if all the arguments are null.

What is the difference between coalesce () and Isnull () with example?

Validations for ISNULL and COALESCE are also different. For example, a NULL value for ISNULL is converted to int though for COALESCE , you must provide a data type. ISNULL takes only two parameters. By contrast COALESCE takes a variable number of parameters.


I have seen both on SO, but I wonder if there is a "best practice" or advantage to coalesce the sum before or after:

coalesce(sum(value),0)  OR  sum(coalesce(value),0)

Just curious...