Search code examples
sqlsql-server-2014

SQL Server: Error converting data type varchar to float with Comma as Decimal point


I stored the values in W10Pro and the decimal values (varchar(50)) cannot be casted to float, I doubt the comma cannot be separated such that commands

SELECT CAST('27,18' as float) 

SELECT CONVERT(float, '27,18')

fire an error Error converting data type varchar to float. How can I fix this?


Solution

  • You can fiddle with internationalization settings, but the easiest way is replace, in my opinion:

    SELECT CAST(REPLACE('27,18', ',', '.') as float)