简体   繁体   中英

Replace Left Outer Join Null values with a string

I want to show the null values returned from the left outer join with a string " UnRegistered".

When the value is an integer or a bool, I just write:

 ISNULL(ReturnedValue, 0) AS ReturnedValue 

but how can I make it:

 ISNULL(ReturnedValue, 'UnRegistered') AS ReturnedValue

I use MS SQL SERVER.

Since you need a varchar value in the same field together with int/bool, you need to make sure every row of that field has the same data type.

Isnull(Convert(varchar(50), ReturnedValue), 'UnRegistered') AS ReturnedValue

Or you can use a CASE as

Case when ReturnedValue is null then 'UnRegistered'
     else convert(varchar(50), ReturnedValue) end as ReturnedValue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM