Skip to content
Advertisement

Conversion failed when converting the varchar value ‘N’ to data type int

I have been finding original balances on bonds from an “Acquisition” table, for individual “performance” quarters. It has worked for every quarter, but when I attempted to run my query on 2010Q1, I received this notice:

My query is:

Zero balance code is telling how the bond defaulted, I am matching between the two tables based on each bonds’ “Loan Identifier”

Thanks! 😀

Advertisement

Answer

Since you have no explicit conversion in the field list, it must be an implicit conversion either in the ON or in the WHERE clause.

For the ON clause to cause a conversion, Loan Identifier would have to be defined as nvarchar in one, and as an int in the other table. This is unlikely (though not impossible 😉

So I suspect your WHERE clause. IF Zero Balance Code is defined as nvarchar and you are comparing with an int (97 or 3), that would cause an implicit conversion. If you have only one entry that contains characters in your table, this implicit conversion will fail. One way to avoid this is to define the WHERE clause with strings (e.g. WHERE A.[Zero Balance Code] = '97', the same for '03'). One slightly more elegant way is to check for numeric data with ISNUMERIC. Because how do you know that the balance code is always '03', and not only '3'? Those entries would be filtered out, because '3' is not equal to '03'

But be careful:
This may be ignoring the real problem. The big question here is, why all of a sudden you have non numeric data in your table! You need to check if you somehow got corrupted data entered into your system.

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