After testing I found that it was not the decimal place that was causing the problem, it was the precision (10)
This doesn't work: Arithmetic overflow error converting varchar to data type numeric.
DECLARE @TestConvert VARCHAR(MAX) = '123456789.12343594'
SELECT CAST(@TestConvert AS DECIMAL(10, 4))
This worked
DECLARE @TestConvert VARCHAR(MAX) = '123456789.12343594'
SELECT CAST(@TestConvert AS DECIMAL(13, 4))
Should be like 9 int + 4 floating = 13 chars
Answer from codingbiz on Stack OverflowAfter testing I found that it was not the decimal place that was causing the problem, it was the precision (10)
This doesn't work: Arithmetic overflow error converting varchar to data type numeric.
DECLARE @TestConvert VARCHAR(MAX) = '123456789.12343594'
SELECT CAST(@TestConvert AS DECIMAL(10, 4))
This worked
DECLARE @TestConvert VARCHAR(MAX) = '123456789.12343594'
SELECT CAST(@TestConvert AS DECIMAL(13, 4))
Should be like 9 int + 4 floating = 13 chars
My explanation is in the code. :)
DECLARE @TestConvert VARCHAR(MAX) = '123456789.1234567'
BEGIN TRY
SELECT CAST(@TestConvert AS DECIMAL(10, 4))
END TRY
BEGIN CATCH
SELECT 'The reason you get the message "' + ERROR_MESSAGE() + '" is because DECIMAL(10, 4) only allows for 4 numbers after the decimal.'
END CATCH
-- Here's one way to truncate the string to a castable value.
SELECT CAST(LEFT(@TestConvert, (CHARINDEX('.', @TestConvert, 1) + 4)) AS DECIMAL(14, 4))
-- If you noticed, I changed it to DECIMAL(14, 4) instead of DECIMAL(10, 4) That's because this number has 14 digits, as proven below.
-- Read this for a better explanation as to what precision, scale and length mean: http://msdn.microsoft.com/en-us/library/ms190476(v=sql.105).aspx
SELECT LEN(LEFT(@TestConvert, (CHARINDEX('.', @TestConvert, 1) + 4)))
sql server - Converting varchar to decimal with truncate - Database Administrators Stack Exchange
How to convert STRING to Decimal in TSQL
Change varchar data type to decimal in SQL
Convert Varchar round value to 2 decimals
Videos
Hello friends,
I have such a situation. I need to change varchar data type into decimal.
CONVERT (VARCHAR, SUM(b.[HistoryQuantity]) / SUM(a.[TOTFCST]) * 100) + โ%โ AS โBiasโ
This is how my bias looks like right now. p.s. The only reason why i wrote Convert Varchar is because I was getting an error without CONVERT(VARCHAR) namely โError converting data type varchar to numericโ.

Does someone know how I can make my bias just a number with two decimal points. Like regular percentage (for ex. 5.22%).
You were likely getting the error because you were trying to insert a non-numeric character (%) into the field. You should just be able to use the FORMAT function to do the percentage formatting for you.
FORMAT(expression,'0.00%')
The issue in the above query is only due to these value (7,956.00 and 5,328.00 ) when casting in implemented on these values the value returned as 7.00 and 5.00 due to which the query gives the result as 2569.00.
Just remove these commas from these numbers and the query will execute properly
SELECT SUM(REPLACE(Amount, ',', '')) as result FROM tblserviceinvoice
You could strip the commas from the number strings before converting them to numbers:
SELECT SUM(CONVERT(REPLACE(amt_tran,",",""),DECIMAL(9,2))) as result
FROM tblserviceinvoice
I have a view consisting of some 90 underlying tables. When working with that view, I get the message 'error when converting datatype to numeric'. After some detective work I found the column resposible for this error. Among the underlying tables, this column is a mixture of decimal(10,2) and numeric(18,2). Both datatypes are functionally equivalent it appears, so I see no problem there. Or am I wrong in this? My primary concern is the mention of 'varchar' in the error message. How is that even possible, as no varchar is involved?
Working on SQL Server 13.0.