SQL - script to round decimalup to the nearest integer - SQL Server 2005

Hello experts,

I have a table with column "level" that holds decimal values.  I have another column called new_number, that I would like to have the level value rounded up to the nearest whole number when the decimal is equal to or greater than .5.  I would like to round down to the nearest whole number if the level value is less than .5:

I currently have:

table: person
level          new_number
1.6            null
0.5            null
11.9            null
8.2            null

and I would like to end up with:


table: person
level          new_number
1.6            2
0.5            1
11.9          12
8.2            8

Something like:

-- first for rounding up
update person
set new_number = dec(round(level / 1, 0)*1,11,0)
where right(level,2) >= .5

-- then for rounding down
update person
set new_number = dec(round(level / 1, 0)*1,11,0)
where right(level,2) < .5

Thoughts?

Thanks!

-Dan
robthomas09Asked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
what about using the function CEILING ?
http://msdn.microsoft.com/en-us/library/ms189818.aspx
0
 
Paul JacksonConnect With a Mentor Software EngineerCommented:
Use CEILING and FLOOR functions to roundup and rounddown
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.