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)
 dividing a smallint datatype

Author  Topic 

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-08-04 : 10:49:00
I have a column named nRUN_TIME that is a smallint. the numbers in this colum are minutes a product ran. so on an average it is anywhere between 84 and 130 minutes. I need to divide this number by 1440 to give me the fraction of a day. for example, I have one record at 136 minutes and I need the results to be 0.094 after I divide it by 1440. If I do this in SQL the number comes out to 0. I tried to convert nRUN_TIME to a decimal and a numeric, but it either gives me errors or I still get a 0. What can I do in this situation?

Thanks!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-08-04 : 10:52:07
[code]declare @nRUN_TIME smallint

select @nRUN_TIME = 136

select @nRUN_TIME / 1440 -- 0

select @nRUN_TIME * 1.0 / 1440 -- 0.094444

select convert(decimal(10,3), @nRUN_TIME * 1.0 / 1440) -- 0.094
[/code]


KH

Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-04 : 10:52:08
U may use either of the following (and many more ways)
1.0 * nRUN_TIME/1440
convert(decimal(10,2),nRUN_TIME)/1440



Srinika
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-08-04 : 10:53:01




KH

Go to Top of Page

chippyles
Yak Posting Veteran

68 Posts

Posted - 2006-08-04 : 11:11:33
thanks!!
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-04 : 11:22:47
quote:
Originally posted by khtan





KH





One Second

Srinika
Go to Top of Page
   

- Advertisement -