+ 1

What does coalesce do ?

24th Mar 2017, 4:59 AM
Dhana Sekar
Dhana Sekar - avatar
3 Answers
+ 1
The COALESCE function in SQL returns the first non-NULL expression among its arguments. Syntax COALESCE ("expression 1", "expressions 2", ...) Example DECLARE @Name 1 varchar(20) DECLARE @Name 2 varchar(20) SET @Name2 = 'Jack' SELECT COALESCE(@Name1, @Name2) As 'Chosen Name' -- Results ========================= Chosen Name ----------- Jack
24th Mar 2017, 5:43 AM
Akwin Lopez
Akwin Lopez - avatar
0
can you explain thé syntax please ? @Akwin
24th Mar 2017, 5:58 AM
Dhana Sekar
Dhana Sekar - avatar
0
Coalesce returns the first non null value. Syntax COALESCE( expression1, expression2, ... expression_n ) Example SELECT COALESCE(NULL, NULL, 'Akwin', NULL, 'Lopez'); result : Akwin the above example returns the first non null value Return Types Returns the data type of expression with the highest data type precedence. If all expressions are nonnullable, the result is typed as nonnullable. Remarks If all arguments are NULL, COALESCE returns NULL. At least one of the null values must be a typed NULL. @Dhana Sekar , Hope I have cleared your doubt
25th Mar 2017, 5:45 AM
Akwin Lopez
Akwin Lopez - avatar