Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Round Up

Author  Topic 

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2003-01-10 : 14:03:06
Has anyone ever tried to design a Round Up Function? I am trying to create a graph and I need to take the largest member in the dataset and round it up.

Any advice?

Jeremy

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-01-10 : 14:19:12
Maybe something like:

select convert(int, @val + .5)

That will round up if @val is .5 or higher. If you ALWAYS want to round up, add .9999999 or something to it.

- Jeff
Go to Top of Page

royv
Constraint Violating Yak Guru

455 Posts

Posted - 2003-01-10 : 14:19:22
If I understand correctly, the CEILING function might be what you are looking for.

***************************************
Death must absolutely come to enemies of the code!
Go to Top of Page

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2003-01-10 : 14:29:01
CEILING will not work the way I need it to. Let me explain a little further. When you have the following table:

October 50
November 100
December 123

I want to take 123 (max value) and round up to 200. I have the following: Round(colValue, Len(colValue)-1). In this case it will round to 100 instead of 200.

Jeremy

Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-01-10 : 15:37:46
Try adding 99 to it before you round.

- Jeff
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-01-10 : 15:48:54
Sounds like you want round to the number of digits?

LEN doesn't tell how many digits are in an integer, just a string/varchar.

I haven't tried this, so it'll need debugging but...

set colValue = ROUND(colvalue, 1-len(cast(colValue as varchar)))

the length value is negative number of digits plus 1.

Maybe there's a better way?

Sam

Go to Top of Page
   

- Advertisement -