SELECT ID,
CASE WHEN ISNUMERIC(COL_VALUE) = 1 THEN CONVERT(NUMERIC, COL_VALUE) * 1000
ELSE COL_VALUE
END AS [COL_VALUE]
FROM Table
The original data type is varchar that is why I convert COL_VALUE to numeric.
It seems like something wrong with ELSE statement, when I execute the query without ELSE statement the non-numeric value will become NULL. I check whether or not the column is numeric, if it is numeric then multiply by 1000, if not numeric then return original value. There are few non-numeric values like:
23`, 34/, 34=4.
CASEexpression, if the value of the column is numeric, you want to return a numeric data type, and if it's not numeric, to return another data type. A column has to be of a single data typeCASEmust resolve to the same type. IfCOL_VALUEhas the possibility of being aVARCHAR, you need to make your first path return aVARCHARas well, like,CAST(CONVERT(NUMERIC, COL_VALUE) * 1000) AS NVARCHAR)TRY_CONVERTinstead ofISNUMERICas well.