Solved

ROUND in SQL query

Posted on 1998-08-31
5
1,061 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

760 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

19 Experts available now in Live!

Get 1:1 Help Now