Solved

rounding the result to near 500's -SQL

Posted on 2012-03-19
9
251 Views
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
0
Comment
Question by:sqlcurious
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Author Comment

by:sqlcurious
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
0
 
LVL 40

Expert Comment

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

Expert Comment

by:Dale Fye (Access MVP)
ID: 37739559
Try:

Round(x/1000)*1000
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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))
0
 
LVL 69

Expert Comment

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

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.
0
 
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))
0
 
LVL 18

Accepted Solution

by:
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
0
 

Author Closing Comment

by:sqlcurious
ID: 37778749
thanks
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

770 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