Replacing NULL and empty string within Select statement
Try this
COALESCE(NULLIF(Address.COUNTRY,''), 'United States')
Sounds like you want a view instead of altering actual table data.
Coalesce(NullIf(rtrim(Address.Country),''),'United States')
This will force your column to be null if it is actually an empty string (or blank string) and then the coalesce will have a null to work with.
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 returnfalse
.
And as documented:NULLIF
is equivalent to a searchedCASE
expression
andCOALESCE
expression is a syntactic shortcut for theCASE
expression.
So, combination of those are using two time ofcase
expression.