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 2012 Forums
 Transact-SQL (2012)
 rounding off the value to next digit

Author  Topic 

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2014-07-01 : 19:52:03
Dear All,

I am processing some list of records and applying the ratio, after that i need to apply the round off fraction to next figure,how can we do this in t-sql.

Ex:
29.4545 --> 30
17.1349 --> 18
16.0201 --> 17

anything fraction digit should come to next round off figures.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-07-01 : 20:35:00
[code] CEILING ( <number> ) [/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2014-07-14 : 01:46:50
quote:
Originally posted by khtan

 CEILING ( <number> ) 



KH
[spoiler]Time is always against us[/spoiler]



Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2014-07-14 : 01:48:00
Hi,even if i need to do the samething for negative number to 0

Ex:

select (-10.33) --> 1
select (10.22) --> 11
select (10.9133) --> 11
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-07-14 : 03:16:22
quote:
Originally posted by gangadhara.ms

Hi,even if i need to do the samething for negative number to 0

Ex:

select (-10.33) --> 1



This is unusual

all negative number return as 1 ?

use CASE statement to do that


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

gangadhara.ms
Aged Yak Warrior

549 Posts

Posted - 2014-07-14 : 12:38:02
Sorry it was my mistake, all negative number should return 0

select (-10.33) --> 0

All negative number should return to 0
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-07-14 : 12:59:47
select case when yourcolumn > 0 then ceiling(yourcolumn) else 0 end
...

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -