Reputation: 37875
I am having a SQL issue, and I have boiled it down to this:
if isnull(5.5,'') = isnull(null,'') select 0 else select 1
which throws the error Error Converting data type varchar to numeric.
Why is this throwing this error, and how to resolve?
Upvotes: 0
Views: 1271
Reputation: 2302
This simpler expression (which is equivalent to your expression) gives the same error:
if 5.5 = '' select 0 else select 1
You're comparing a varchar to a numeric type as the error indicates.
You can CAST
your expression to match types:
if CAST(isnull(5.5,'') AS VARCHAR) = isnull(null,'') select 0 else select 1
Upvotes: 2