Replacing NULL and empty string within Select statement

前端 未结 4 822
栀梦
栀梦 2020-12-03 05:20

I have a column that can have either NULL or empty space (i.e. \'\') values. I would like to replace both of those values with a valid value like

4条回答
  •  星月不相逢
    2020-12-03 06:06

    An alternative way can be this: - recommended as using just one expression -

    case when address.country <> '' then address.country
    else 'United States'
    end as country
    

    Note: Result of checking null by <> operator will return false.
    And as documented: NULLIF is equivalent to a searched CASE expression
    and COALESCE expression is a syntactic shortcut for the CASE expression.
    So, combination of those are using two time of case expression.

提交回复
热议问题