Solved

SQL Syntax for rounding up

Posted on 2013-01-28
8
181 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
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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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