-2

How to replace NULL value of specific column with other column value. For example: If second name of customer is not given then add father name in second name column.

2

5 Answers 5

1

Try with case statement as below-

SELECT
CASE 
    WHEN second_name IS NULL OR second_name = '' THEN father_name 
    ELSE second_name
END AS second_name
FROM your_table
Sign up to request clarification or add additional context in comments.

2 Comments

thanks now there is one more condition of middle name null
No matter what can be done, its all depends on what you wants? Just explain your requirement. There is always a solution. :)
1

use coalesce()

select coalesce(secondname ,fathername) from tablename

Comments

1

You can use COALESE

SELECT COALESE(second_name, first_name) from mytable;

AFAIK, it is supported on Oracle, MS SQL Server, MySQL and Postgres.

Comments

0

You can use ifnull function as well. The syntax should be like :

select ifnull(second_name,father_name) from user;

Comments

0
SELECT COALESCE(NULLIF(second_name, ''), father_name) from table

You can handle blank and NULL values in the second_name column and if these values are there it will show value from father_name column

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.