NVARCHAR to Decimal Error

I have an Case when statement that goes like this:

Case When OH > 0 then OH-Calculated_Sugg else ’ ’ end

This always errors out as an NVARCHAR to Decimal conversion failure. When I put a zero in, it works. How can I get it to be blank if its less than zero.

@Will79 If this calculated field returns a decimal data type, then feeding it an empty string will throw the error. Try NULL after the “else” in your code instead.

2 Likes

I think using IsNull with a default of zero might resolve a null “OH” issue:

Case When IsNull(OH, 0) > 0 then OH-Calculated_Sugg else 0 end

But, you have two different types on your output / then statement:
“OH - Calculated_Sugg” is a number.
and
“’’” is a string

Make the else a zero too. Or convert you number calculation to a string.

1 Like