I am trying to store a value stored as a varchar in a decimal field.
The following examples all results in: “Error converting data type varchar to numeric.”
what am i missing here ?
SELECT CONVERT(decimal(11,2), '6.999,50')
SELECT CONVERT(decimal(11, 2), '6.999,50')
SELECT CAST('6.999,50' AS decimal) / 100.0
SELECT CAST((CAST('6.999,50' AS decimal) / 100000) AS decimal(17,5))
You are missing the fact that 6.999,50 is not a valid decimal. You can’t have a comma and a decimal point in a decimal value surely? What number is it supposed to be?
Assuming your locale specifies . as grouping and , as decimal separator:
To remove the grouping digits:
will yield 6999,50 as a decimal