Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
1 like 0 dislike
2.2k views
in SQL Queries by 21 20 26

I have created a new EmployeeManager table in the sql server. but when I selected a data from database I get NULL values

select * from EmployeeManager

How can I replace the NULL with this value 'No manager'  as a default value in the SQL query result?


1 Answer

2 like 0 dislike
by 22 25 39

There are three ways to replace the NULL value with default values

1) You can use ISNULL function to replace Null with No manager

Select ISNULL(NULL,'No manager') 

2) You can use the COAlESCE function

Select  CoalEscE(NULL,'No manager' )

3) Case statement

select Case when Name is null then 'No manager' else  Name  end  
 from Employee

You can see also ISNULL (Transact-SQL)

If you don’t ask, the answer is always NO!
...