Skip to content
Advertisement

Convert Null to text on numeric field

I have a query that LEFT joins 4 different tables. There will always be a match in one of these tables but we don’t know which one. When the query is executed there are some fields producing NULL values. These are float fields but I was wondering if there is a way to change the Null to some kind of indicator such as “No Coverage”?

I have attempted something simple such as:

ISNULL(acccoverage, 'No Coverage') AS acccoverage

However when I run this I get the following error message:

Error converting data type varchar to float.

I’m sure its something simple but I have tried CONVERT and CAST but with no joy.

Thanks in advance

Advertisement

Answer

First, use COALESCE(). It is the standard function. Then convert the number to a string:

COALESCE(CONVERT(VARCHAR(255), acccoverage), 'No Coverage')

You can do the same thing with ISNULL().

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement