Replacing Null values with Empty strings or other custom values in SQL using ‘Coalesce()’ and ‘ISNULL()’ functions. In this article, we will learn How to Replace Null with Empty String in SQL Using Coalesce | ISNULL function.
Coalesce Function
The COALESCE() function can take multiple arguments and return the first non-null value from the list of arguments. For example:
Select coalesce(null,'Hight',null,'Low') as 'coalesce function'
The above query returns the second value because it considers the second value as the first value that isn’t null.
Replace Null with Empty String Using Coalesce Function
-- Replace Null with Empty string
select Company,[First Name],[Last Name], coalesce([E-mail Address],'') as email from [dbo].[Customers]
-- Replace Null with custom value
select Company,[First Name],[Last Name], coalesce([E-mail Address],'Email address missing') as email from [dbo].[Customers]
Result:
ISNULL Function
The ISNULL() function takes two arguments. It returns the not null value first. For example
Select ISNULL('Hight',null) as 'ISNULL function'
Replace Null with Empty String Using ISNULL Function
select Company,[First Name],[Last Name], ISNULL([E-mail Address],'') as email from [dbo].[Customers]
Result