F
F
Fedor Zhekov2016-11-28 17:24:34
Transact SQL
Fedor Zhekov, 2016-11-28 17:24:34

How to convert from varchar to real in MSSQL?

Good afternoon!
There is a line:

declare @point varchar (100) = '-27,452;26,491;4,299'

I divide it by the symbol ";" and I want to write to a variable of type real:
declare @index int
declare @x real
select @index = CHARINDEX(';', @point)
select @x = cast(substring(@point, 0, @index) as real);

I am getting an error:
Сообщение 8114, уровень 16, состояние 5, строка 41
Ошибка при преобразовании типа данных varchar к real.

When using convert:
select @x = convert(real, substring(@point, 0, @index));

I get the same error
Question removed. It was necessary to replace the symbol "," with the symbol ".":
select @x = convert(real, replace(substring(@point, 0, @index), ',', '.'));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question