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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Ceiling Function
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rheinhardt
Yak Posting Veteran

South Africa
66 Posts

Posted - 10/08/2009 :  07:03:43  Show Profile  Reply with Quote
Hi,

I would like to make two columns one where the figures are rounded up that has >0.4 and one that has figures rounded <0.5?

Please assist.

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 10/08/2009 :  07:07:32  Show Profile  Visit SwePeso's Homepage  Reply with Quote
What about 0.45?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Rheinhardt
Yak Posting Veteran

South Africa
66 Posts

Posted - 10/08/2009 :  07:10:08  Show Profile  Reply with Quote
:)Ok so if you understand what the idea is what would you recommend.I want to have 2 columns to show the effects of the rounding?
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2875 Posts

Posted - 10/08/2009 :  08:12:15  Show Profile  Reply with Quote
SELECT Col1,[RoundedUp] = CASE WHEN col >= .5 CEILING(Col1) ELSE 0 END
,[RoundedDown] = CASE WHEN col < .5 FLOOR(Col1) ELSE 0 END
FROM yourTable

You can put whatever you want for the ELSE part (col1, null, etc.)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22864 Posts

Posted - 10/08/2009 :  08:28:38  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
select col,floor(col+0.5),floor(col) FROM
(
select '0.45' as col union all select '0.3'
) yourTable


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000