Convert to decimal without adding zeros - SQL Server

0

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

Example: 12,345.67 --- > 1234567,00

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

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

    
asked by anonymous 11.07.2018 / 21:33

1 answer

0

The number should have this format '12345.67', so first remove the dot, then replace the comma with dot, like this:

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

Here's a working example: link

    
11.07.2018 / 21:37