Convert to decimal without adding zeros - SQL Server

Asked

Viewed 858 times

0

I am converting a number from varchar to decimal. This number already has the boxes after the comma, and when I convert it adds 2 more zeros.

Example: 12.345,67 ---> 1234567,00

The code I’m using is this: CAST(REPLACE( REPLACE(ZMI058.Amount, ',', '), '.', ') AS decimal(18,2)) AS Amount

How do I play the numbers I already have to the decimal places?

1 answer

0


The number must have this '12345.67' format, so first remove the dot, then replace the comma by a dot, like this:

select CAST(REPLACE( REPLACE(ZMI058.Montante, '.', ''), ',', '.') AS decimal(18,2)) AS Montante

See here an example working: http://sqlfiddle.com/#! 18/5e0e9/1

  • It worked perfectly! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.