How to SELECT round up number in SQL Server

前端 未结 5 1869
南方客
南方客 2021-01-25 08:44

I have a salary table with this column

EMPLOYEE_NAME    SALARY
------------------------
ANNA             113750
MARRY            124300
BELLA            105100
<         


        
5条回答
  •  无人共我
    2021-01-25 09:17

    Unlike ROUND (which rounds up and down) the CELING function (which you want to round up) has no length parameter (as in ROUND(salary, -3)). So divide and multiply to get the desired result:

    select employee_name, ceiling(salary / 1000.0) * 1000.0 as salary
    from mytable;
    
    • CEILING is documented here: https://msdn.microsoft.com/de-de/library/ms189818.aspx
    • ROUND is documented here: https://msdn.microsoft.com/de-de/library/ms175003.aspx

提交回复
热议问题