Writing a Case Statement select another field value if primary field value is blank

So I am trying to write a Case statement to select a different field to pull a value when the primary field has a blank value… Something like:

CASE Parent Carrier ID
WHEN 'null' THEN Carrier Name
ELSE Parent Carrier Name
END

I don't know what to enter as a valid term for ‘null’ to represent looking for empty values?

Answers

  • Figured it out:

    CASE IFNULL(Parent Carrier ID, 'null')
    WHEN 'null' THEN Carrier Name
    ELSE Parent Carrier Name
    END

  • @Clinton Your logic should work, though for future reference you can simplify it using an “is null” operator like below:

    case when Parent Carrier ID is NULL then Carrier Name else Parent Carrier Name end