Case Function with Is Null

How do I implement such scenario in Teradata

If Col1 is null or if Col1 = ''Jack'' then Col2 else Col1

I ha e implemented it but for some reason it's not working may be some issue with Bracketay

2 Answers

You can also use the NULLIF() operator:

COALESCE(NULLIF(col1,'Jack'), col2) 

This is logically equivalent to the CASE statement in the previous answer.

1

You can use a case expression:

case 
  when col1 is null or col1 = 'Jack' then col2
  else col1
end

String (varchar) constants need to be enclosed in sinqle quotes in SQL.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest