VARCHAR to DECIMAL

前端 未结 12 671
清歌不尽
清歌不尽 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:42

    Your major problem is not the stuff to the right of the decimal, it is the stuff to the left. The two values in your type declaration are precision and scale.

    From MSDN: "Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2."

    If you specify (10, 4), that means you can only store 6 digits to the left of the decimal, or a max number of 999999.9999. Anything bigger than that will cause an overflow.

提交回复
热议问题