Home > Software engineering >  SQL convert nvarchar into decimal dynamic rows
SQL convert nvarchar into decimal dynamic rows

Time:10-29

I am not so familiar with using convert in SQL so thats why i am stuck with the following situation:

The column has a nvarchar(max) and i would like to convert it into decimal (18,2). But there are some rows that consist a "full" amount (see red box). For all values with the full amount i would like to have it as 1222,00

enter image description here

When creating a SQL view I got this error: Error converting data type nvarchar to numeric.

enter image description here How can i still convert this column into decimal?

Many thanks

CodePudding user response:

From your pictures it seems to me like you are using SQL-Server. If so your problem is having , as decimal point instead of . It has nothing to do with having whole and decimal numbers in your data.

So you should replace it before converting data.

SELECT CONVERT(decimal(18,2), REPLACE(ColumnName,',','.')) FROM TableName

DB<>fiddle

  • Related