How to SELECT round up number in SQL Server

前端 未结 5 1862
南方客
南方客 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:00

    Divide the salary by the fraction. Use ceiling to round up. Then multiply by the fraction.

    Declare @salary table (Employee_name nvarchar(50), Salary money)
    Declare @fraction money = 5000
    
    insert into @salary
    values
    ('ANNA',             113750),
    ('MARRY',           124300),
    ('BELLA',           105100)
    
    update @salary
    set Salary = ceiling(salary/@fraction)*@fraction
    
    select * from @salary
    

提交回复
热议问题