SQL COALESCE Function

The COALESCE function in SQL returns the first non-NULL expression among its arguments.

Table Info

Name

Bussiness_Phone




Cell_Phone

Home_Phone

Gaurang

5646




95855

456

Jinal

Null




783

null

Brijesh

Null




Null

465465

If You Used Case When the Query Is :

 Select Name,Case  When Business_Phone is null Then Case When Cell_Phone is null Then Home_Phone Else Cell_Phone End
           Else Business_Phone End As Phone From test


If You Used Isnull Function :

Select Name,Isnull(Business_Phone,Isnull(Cell_Phone,Home_Phone)) From test

If You Used Coalesce Function :

Select Client_Name,Coalesce(Business_Phone,Cell_Phone,Home_Phone) From test

-------------------------------------

Thanks & Regards

Gaurang Upadhyay

Sr Developer


Ebook Download
View all
Learn
View all