# Rounding Up

Hi

SQL 2008

I am trying to round up a division I am doing so  as follows

For example I have data for a duration of 740 secs, I want to convert this into minutes (740/60).
The answer would be 12.33 (displayed in SQL as 12). I want to round this up to the next whole number which would be 13. IF it was 720 secs that would stay at 12

How can this be done

Thanks
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Microsoft SQL Server Developer, Architect, and AuthorCommented:
What's the logic for rounding up vs. down?  Does 12.01 round up to 13 or stay at 12?
So far..
``````Declare @numerator int = 740, @denominator int = 60

SELECT CAST(@numerator as decimal(9,2)) / @denominator as decimal_value

-- If 12.01 rounds up to 13
SELECT CASE
WHEN @numerator / @denominator = CAST(@numerator as decimal(9,2)) / @denominator THEN @numerator / @denominator
ELSE @numerator / @denominator + 1 END as integer_value
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Senior DeveloperCommented:
12,33 are 12 hours and 20 minutes. Why rounding to 13?
0
Information Technology SpecialistCommented:
The ceiling function should do what you want.
ceiling(740/60) => 13
0
is 1 second = to 1 minute?

``````select
secs
, case when secs % 60 = 0 then secs / 60 else (secs / 60) + 1 end
from table1
``````

``````| SECS | COLUMN_1 |
|------|----------|
|    1 |        1 |
|    2 |        1 |
|    3 |        1 |
..
|   59 |        1 |
|   60 |        1 |
|   61 |        2 |
...
|  739 |       13 |
|  740 |       13 |
|  741 |       13 |
--
``````
see http://sqlfiddle.com/#!3/19a0a/2
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.