Sql Rounding

I'm having some trouble coming up with a solution for this.  In one of my procs I get a certain number.  If this number is greater than 125000 I have to round to the nearest 5000.  If it is less that 125000 I have to round to the nearest 2500.  I'm pretty new to Sql Server so any help would be appreciated!
oak29Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jogosCommented:
something like this
declare @x as int
set @x = 132502
select case when @x > 12500 
		then round(@x/5000,0) * 5000
		else round(@x/2500,0) * 2500
       end

Open in new window

0
gdupadhyayCommented:

You can do:
IF @Number > 125000
      BEGIN
            SET @Number =  5000
      END
IF @Number < 125000
      BEGIN
            SET @Number =  2500
      END

Let me know if your looking for some different.
0
Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
Hi,
you can use following logic,

just  ignore following when implementing

Declare @val as int
Set @val = 1000000
...
Print(@val)


 
Declare @val as int
Set @val = 1000000
IF @val > 125000
	SET @val =  5000
Else IF @val < 125000
	SET @val =  2500


Print(@val)

Open in new window

0
jogosCommented:
Sorry, by using INT it was always a truncation.

declare @y as numeric(18,2)
declare @x as numeric(18,2)
set @x = 132502

-- assign it to a variable
set @y=case when @x > 125000 
		then round(@x/5000,0,0) * 5000
		else round(@x/2500,0) * 2500
       end

-- use it directly in a query
select case when @x > 125000 
		then round(@x/5000,0,0) * 5000
		else round(@x/2500,0) * 2500
       end

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oak29Author Commented:
That works really well.  Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.