Ayman Ayman - 3 months ago 18
SQL Question

Select ISNULL is not returning replacement value

ContactPerson
type is nvarchar.

The issue is when
ContactPerson
is empty not returning
n/a


Query

Select ISNULL(ContactPerson,'n/a') from [dbo].[Suppliers]

Answer

An empty string ('') and not the same thing as a null value. ISNULL() returns the replacement value only for an actual null value.

You can use NULLIF() to evaluate an empty string into a null value:

SELECT ISNULL(NULLIF(ContactPerson, ''), 'n/a') ...