Solved

ROUND in SQL query

Posted on 1998-08-31
5
1,086 Views
Last Modified: 2012-06-27
In a SQL query, I use the ROUND function  to round a double type field with n decimals. The problem is that it rounds to the closiest even number, and I'd like to round to  the closiest integer !
For example : ROUND(1.5 , 0) ==> 2
                      ROUND(2.5 , 0) ==> 2

I want : MyFunction(1.5, 0) ==> 2
             MyFunction(2.5, 0) ==> 3

Same thing with n decimals
(I have a solution in ACCESS but not in SQL-SERVER and ORACLE: under ACCESS it is like that :
...SET amount =  fix(amount*rate*10^NbDecimals+0.5)/10^NbDecimals

Thank you for help.
0
Comment
Question by:gosselin
  • 3
5 Comments
 
LVL 2

Expert Comment

by:threshold
ID: 1089858
In my SQL Server 6.5, i got

ROUND(2.5 , 0) ==> 3
0
 

Author Comment

by:gosselin
ID: 1089859
Your are rigth. This result is obtain with the CLng function of ACCESS, I was completly wrong. So there is no question any more.

Thank you very much
How can I give you the points ?

0
 
LVL 2

Expert Comment

by:threshold
ID: 1089860
You r welcomed.
Keep it...
Delete the question...
0
 
LVL 3

Expert Comment

by:altena
ID: 1089861
You really deserve the points treshold.

Its the little things like this that can really
eat one's time away. And with hindsight it is
oh so simple :-)

---Cheers
0
 
LVL 2

Accepted Solution

by:
threshold earned 300 total points
ID: 1089862
Ok, Thanks.... I repost my 'note' again.

In my SQL Server 6.5, i got
ROUND(2.5 , 0) ==> 3
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

829 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