VARCHAR to DECIMAL

前端 未结 12 672
清歌不尽
清歌不尽 2020-12-06 09:24

I want to convert a varchar(max) column to decimal(10,4).

When I try to use cast or convert I am getting an arit

12条回答
  •  清歌不尽
    2020-12-06 09:44

    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(18, 4))
    

提交回复
热议问题