Don't know why this conversion fails.
SELECT CAST('32.999' AS INT)
throws the error saying
开发者_如何学PythonConversion failed when converting the varchar value '32.000' to data type int.
I know I can convert it to Decimal
and then convert it to Int
but why 32.000 is not being converted to Int
directly?
Am I missing something here?
--EDIT--
I don't care about the decimal points. I want SQL to ignore them.
32.000 can not be represented accurately as an int due to the decimal places. Instead, if you want a numeric value with decimals, you can use a float (or numeric) data type.
Select CAST('32.000' as float)
edit: misread your question a little bit.
I'm assuming SQL is trying it's best to preserve your intentions. When it reads in that the numeric value you're attempting to cast has decimal values, it will flat out reject it.
used SELECT CAST(ROUND('32.999',0,1) AS INT)
and it works well.
精彩评论