Solved

SQL Syntax for rounding up

Posted on 2013-01-28
8
184 Views
Last Modified: 2013-01-29
I've got numbers like 3.32 and 3.87 that I calculate and I would like them to both round up to 4 however what I'm getting is rounding down.

Looking at some other questions that were answered I thought this might pull it off but to no avail?

CAST(ROUND(CAST(C.TRANS_QTY AS decimal(18,2)),0) AS INT) AS ROUNDED_QTY,

This does deliver a '0' decimal but it is not rounding up. i suspect I have the cast and round bits scewing with one another.

Thanks!
0
Comment
Question by:ghettocounselor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 12

Expert Comment

by:Tony303
ID: 38829402
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 38829409
What version of SQL SErver. Froim 2008r2 there is the roundup function.
ROUNDUP(C.TRANS_QTY,0) should do it.


Kelvin
0
 
LVL 12

Accepted Solution

by:
Tony303 earned 500 total points
ID: 38829411
SELECT CEILING(yourNumber)
0
Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 38829413
You may also need a cast statement with the column being passed.

Kelvin
0
 
LVL 12

Expert Comment

by:Tony303
ID: 38829424
SELECT CEILING(CAST(C.TRANS_QTY AS decimal(18,2))) AS ROUNDED_QTY
0
 
LVL 10

Expert Comment

by:deviprasadg
ID: 38830451
CAST(CEILING(C.TRANS_QTY) AS INT)  AS ROUNDED_QTY,
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 38831068
Froim 2008r2 there is the roundup function.
ROUNDUP(C.TRANS_QTY,0) should do it.

Not in T-SQL.  I suspect you are thinking of DAX functions.
0
 

Author Closing Comment

by:ghettocounselor
ID: 38831388
in SQL Server 2008 R2 ceiling worked, there seems to be no 'roundup' command.
0

Featured Post

Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question