rounding the result to near 500's -SQL

Posted on 2012-03-19
Last Modified: 2012-03-28
Hi experts I have column which gives the following results(CAST(MAX(DISTINCT i.invoice_amt) AS INT)) and I was asked to round it to the nearest 500, was wondering how I could achieve that, please help:
original result-expected result
21937.5 - 22000
3528 - 3500
4904.25 - 5000
17154.75 -17000
25938.75 - 26000
2209.5 - 2000
2760- 3000
Question by:sqlcurious
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2

Author Comment

ID: 37739510
I tried the below and it works for most of the numbers but doesnt for 2760. For 2760 I am getting 2500 but would need 3000 as a result, please help

SELECT ROUND ( column/500 , 0, 0)*500
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 37739558
select round(@number/ 500) * 500
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 37739559

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

LVL 69

Expert Comment

by:Scott Pletcher
ID: 37739576
You can round to even 100 like so:

(CAST(ROUND(MAX(DISTINCT i.invoice_amt), -2) AS INT))
LVL 69

Expert Comment

by:Scott Pletcher
ID: 37739581
Now we "just" have to go from 100s to 500s :-) .
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 37739582
Duh, that won't work, but Round(x/500)*500 works fine on my Access system.
LVL 69

Expert Comment

by:Scott Pletcher
ID: 37739604
Never mind.  Hopefully this will do the whole thing in one shot

(CAST((MAX(DISTINCT i.invoice_amt) + 250.0) / 500.0 * 500.0 AS INT))
LVL 18

Accepted Solution

deighton earned 500 total points
ID: 37742738
SELECT ROUND ( column/500.0 , 0, 0)*500

just put the 500.0 in the divisor to make it do the calc as a float

Author Closing Comment

ID: 37778749

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

752 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