How could I convert this
into this?
Advertisement
Answer
You can use coalesce()
and a case
expression:
select coalesce(col1, col2) as col3, (case when col1 is null then 'Add' else 'Remove' end) as col4 from t where col1 is null or col2 is null;
EDIT:
You should fix your data model. Until then, you can cast()
the values:
coalesce(cast(col1 as nvarchar2(255)), cast(col2 as nvarchar2(255))
You don’t really need to cast both values, but I don’t want to remember which column has which type.