SQL - How do I get only the numbers after the decimal?

后端 未结 12 2113
清酒与你
清酒与你 2020-12-03 00:57

How do I get only the numbers after the decimal?

Example: 2.938 = 938

12条回答
  •  广开言路
    2020-12-03 01:15

    You can use FLOOR:

    select x, ABS(x) - FLOOR(ABS(x))
    from (
        select 2.938 as x
    ) a
    

    Output:

    x                                       
    -------- ----------
    2.938    0.938
    

    Or you can use SUBSTRING:

    select x, SUBSTRING(cast(x as varchar(max)), charindex(cast(x as varchar(max)), '.') + 3, len(cast(x as varchar(max))))
    from (
        select 2.938 as x
    ) a
    

提交回复
热议问题