COALESCE():-
COALESCE is a function in SQL Server which returns the first non NULL expression amongst its parameter. If all the parameters are evaluated to NULL, It will return NULL
Syntex:-
COALESCE( expression1, expression2, ... expression_n )
Here expression1 to expression_n are the parameters to COALESCE function. Unlike ISNULL which takes 2 parameter COALESCE can have n parameters
Example:-
I am using the below script to create the table
CREATE TABLE EmpDetail
(
Id INT IDENTITY(1,1),
Name NVARCHAR(20),
MobileNo NVARCHAR(10),
PhoneNo NVARCHAR(15),
AlternateNo NVARCHAR(15)
)
and i am using the below sample data
INSERT INTO EmpDetail VALUES('A','7894561230',NULL,NULL),
('B',NULL,'011-9632',NULL),
('C',NULL,NULL,'9638527410'),
('D','3692581470','022-3215',NULL)
And here is the result
Here in above query we can see COALESCE function return the first non null values amongst its parameter
0 Comment(s)