I have a table with numbers in the varchar(255) field varchar(255) . They are more than one and have several decimal places. I would like to convert them to integers. According to every website I have consulted, including https://stackoverflow.com/a/312960/ , any of these should work:
SELECT CAST(VarcharCol AS INT) FROM MyTable SELECT CONVERT(INT, VarcharCol) FROM MyTable
They work for me for every kind of numeric value, but integer - I can convert to float , decimal , etc., just fine, but trying to convert to integer gives me the following error:
Conversion failed when converting the varchar value '7082.7758172' to data type int.
I worked on the problem by going over to the Decimal(6,0) data type, which works fine. But just for my training, can someone tell me why converting to an int (or integer ) data type gives me an error? Thanks.
source share