Link to home
Start Free TrialLog in
Avatar of oak29
oak29

asked on

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!
Avatar of jogos
jogos
Flag of Belgium image

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


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.
Avatar of Imran Javed Zia
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

ASKER CERTIFIED SOLUTION
Avatar of jogos
jogos
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oak29
oak29

ASKER

That works really well.  Thanks!