COALESCE and REPLACE Function

前端 未结 1 830
夕颜
夕颜 2021-01-29 02:01

I am trying to replace all null values in my query with \'\' as our interface won\'t accept NULL as an entry. Ive run into a piece of my code where im using the REPLACE functi

1条回答
  •  别那么骄傲
    2021-01-29 02:58

    You can use the isnull function to replace null values:

    replace(isnull(clients.CLIENT_ID_2, ''),'-','') as PatientSSN
    

    The coalesce function can also be used in the same way. The only difference between isnull and coalesce is that isnull is specially intended to replace a null value so it only takes two parameter.

    You can also use a case, then it would be:

    case
      when clients.client_id_2 is null then ''
      else replace(clients.CLIENT_ID_2,'-','')
    end as PatientSSN,
    

    0 讨论(0)
提交回复
热议问题