SQL Server: Error converting data type nvarchar to numeric

前端 未结 3 680
时光说笑
时光说笑 2020-12-29 10:05

If I run the SQL query below; I get the following error:

Error converting data type nvarchar to numeric.

COLUMNA c

3条回答
  •  轮回少年
    2020-12-29 10:38

    You might need to revise the data in the column, but anyway you can do one of the following:-

    1- check if it is numeric then convert it else put another value like 0

    Select COLUMNA AS COLUMNA_s, CASE WHEN Isnumeric(COLUMNA) = 1
    THEN CONVERT(DECIMAL(18,2),COLUMNA) 
    ELSE 0 END AS COLUMNA
    

    2- select only numeric values from the column

    SELECT COLUMNA AS COLUMNA_s ,CONVERT(DECIMAL(18,2),COLUMNA) AS COLUMNA
    where Isnumeric(COLUMNA) = 1
    

提交回复
热议问题