It accepts pretty much any number of parameters, but they should be the same data-type. (If they're not the same data-type, they get implicitly cast to an appropriate data-type using data-type order of precedence.)
It's like ISNULL() but for multiple parameters, rather than just two.
I've been told that COALESCE is less costly than ISNULL, but research doesn't indicate that. ISNULL takes only two parameters, the field being evaluated for NULL, and the result you want if it is evaluated as NULL. COALESCE will take any number of parameters, and return the first value encountered that isn't NULL.
Coalesce() function evaluates all passed arguments then returns the value of the first instance of the argument that did not evaluate to a NULL.
Note: it evaluates ALL parameters, i.e. does not skip evaluation of the argument(s) on the right side of the returned/NOT NULL parameter.
Syntax:
Coalesce(arg1, arg2, argN...)
Beware:
Apart from the arguments that evaluate to NULL, all other (NOT-NULL) arguments must either be of same datatype or must be of matching-types (that can be "implicitly auto-converted" into a compatible datatype), see examples below:
PRINT COALESCE(NULL, ('str-'+'1'), 'x') --returns 'str-1, works as all args (excluding NULLs) are of same VARCHAR type.
--PRINT COALESCE(NULL, 'text', '3', 3) --ERROR: passed args are NOT matching type / can't be implicitly converted.
PRINT COALESCE(NULL, 3, 7.0/2, 1.99) --returns 3.0, works fine as implicit conversion into FLOAT type takes place.
PRINT COALESCE(NULL, '1995-01-31', 'str') --returns '2018-11-16', works fine as implicit conversion into VARCHAR occurs.
DECLARE @dt DATE = getdate()
PRINT COALESCE(NULL, @dt, '1995-01-31') --returns today's date, works fine as implicit conversion into DATE type occurs.
--DATE comes before VARCHAR (works):
PRINT COALESCE(NULL, @dt, 'str') --returns '2018-11-16', works fine as implicit conversion of Date into VARCHAR occurs.
--VARCHAR comes before DATE (does NOT work):
PRINT COALESCE(NULL, 'str', @dt) --ERROR: passed args are NOT matching type, can't auto-cast 'str' into Date type.
coalesce take n number of arguments from left to right. coalesce selects the first non null argument. similarly isnull(field,'unknown') is equivalent to coalesce(field,'unknown') with the difference that coalesce can compare multiple fields.