Hi @Nandu S Raj
So the presence of integer '-1' forces sql server to try and convert the varchar constant to integer, but it fails to do so why?
The reason is a varchar value could contain characters not just numeric values. It is hard to build a logic to handle the convert behavior.
As we know, not only a varchar like '123.800' to an int but also these conversations: varchar 'A123' or '123.8,123.6' to int will be failed. SQL Server doesn't know how to handle the non-numeric characters or decimals in a varchar string.
However, when converting between numeric types like float or decimal to int, the logic is simple, SQL Server will just truncate the decimal part because it knows it is safe to remove the decimal part.
Therefore, when trying to convert a varchar to int, SQL Server expects the varchar to contain only solid int values.
Best regards,
Cosmog
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".