I have simple code. I need make easy operation: "column_A * 100 ", but I can't convert varchar type to int. My error is: Conversion failed when converting the varchar value '0.27' to data type int.
SELECT POWIERZCHNIA,
POWIERZCHNIA * 100
FROM v_analiza_cechy_produktow
--Conversion failed when converting the varchar value '0,27' to data type int.
SELECT POWIERZCHNIA,
CAST (REPLACE(POWIERZCHNIA, ',' , '.') AS int)
FROM v_analiza_cechy_produktow
--Conversion failed when converting the varchar value '0.27' to data type int.
I want convert this values to int, but how?
@Larnu
SELECT POWIERZCHNIA FROM v_analiza_cechy_produktow
WHERE TRY_CONVERT(decimal(10,4),POWIERZCHNIA) IS NULL;
TOP 20 rows:
NULL 1,08 0,21 0,85 1,38 0,00 2,88 3,00 2,40 1,00 1,36 0,30 2,16 3,24 NULL NULL NULL 2,88
Do not understand why you want to replace , to . and then still cast as INT..., there is no point to do this. Below should work fine, please test it.
EDIT
It is basically the same answer as @Larnu, just used CAST instead of CONVERT...
EDIT
You can use ISNUMERIC function to check POWIERZCHNIA