Data Conversion ( varchar to decimal)

  • Hi,

    I am having trouble in convert the data from one data type to another. I have a column which is declared as varchar(100) and it contains decimal values like

    column

    --------

    0.4567777777778999999999345677777777777777777

    10.3456789002322222222222545465565767888888888888888

    I want to convert this and place into another column which is of type decimal(10,4). The problem is the column contains more than 38 digits which is the maximum precision for decimals provided by sql server. So I'm getting error 'arithmetic out of range exception' while trying to use convert function. How should I do this? Please let me know.

    I need the result to be

    column

    ---------

    0.4567

    10.3456

    Thanks,

    Sridhar!!

  • Would this work for you? 

    CONVERT(DECIMAL(10,4),LEFT(@test), @@MAX_PRECISION))

    Where @test-2 is the numeric value (varchar)

  • Sorry typo

    CONVERT(DECIMAL(10,4), LEFT(@test, @@MAX_PRECISION))

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply