1

In SQL Server, how to write a query in case ItemType = MD5 then replace Null value as 'NAM' ?

 Country ItemType
  Null    MD5

1 Answer 1

2

Use CASE EXPRESSION :

SELECT CASE WHEN t.ItemType = 'MD5' THEN 'NAM' ELSE t.country END as [Country],
       t.itemType
FROM YourTable t

If you want it only to be replace when Country is NULL, then replace it with this:

CASE WHEN t.ItemType = 'MD5' AND t.country IS NULL THEN 'NAM' ELSE t.country END
Sign up to request clarification or add additional context in comments.

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.