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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top