Solved

SQL Syntax for rounding up

Posted on 2013-01-28
8
179 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
 
LVL 22

Expert Comment

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

Kelvin
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now