sql >> Base de Datos >  >> RDS >> Sqlserver

mssql convertir varchar a flotante

Puede convertir varchars en flotantes, y puede hacerlo de la manera que ha expresado. Su varchar no debe ser un valor numérico. Debe haber algo más en ello. Puede usar IsNumeric para probarlo. Mira esto:

declare @thing varchar(100)

select @thing = '122.332'

--This returns 1 since it is numeric.
select isnumeric(@thing)

--This converts just fine.
select convert(float,@thing)

select @thing = '122.332.'

--This returns 0 since it is not numeric.
select isnumeric(@thing)

--This convert throws.
select convert(float,@thing)