Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello All,

I am working on converting MS Access macros to sql,
While i converting i faced one serious issue.

Though ms access and sql are Microsoft product conversion of number works differently.
Ex.
IN MS ACCESS
546.5 =546
546.6=547
546.4=546

Whether in SQL
546.5 =547
546.6=547
546.4=546

I want to round function like how it works in MS Access
546.5 =546
546.6=547
546.4=546

What I have tried:

select cast(round(2764.6,0) as int)
Posted
Updated 8-Feb-18 22:06pm

If your numbers only have one decimal position (that is there are no number like 546.51 or 546.49) you can use:
SQL
select cast(round(x-0.01,0) as int
 
Share this answer
 
Comments
sunil mali 9-Feb-18 4:03am    
Exact output as per my expectation :) 5/5
Thank you so much..
Take a look at MS Access documentation:
Quote:

The Microsoft Access Round function returns a number rounded to a specified number of decimal places. However, the Round function behaves a little peculiar and uses something commonly referred to as bankers rounding. So before using this function, please read the following:

The Round function utilizes round-to-even logic. If the expression that you are rounding ends with a 5, the Round function will round the expression so that the last digit is an even number.


Conclusion: you have to create custom function which will behave as you expected

Source:
MS Access: Round Function[^]
ROUND (Transact-SQL) | Microsoft Docs[^]
 
Share this answer
 
Comments
sunil mali 13-Feb-18 0:17am    
Thank you so much sir..
Maciej Los 13-Feb-18 1:46am    
You're very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900