SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 dividing a smallint datatype
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chippyles
Yak Posting Veteran

68 Posts

Posted - 08/04/2006 :  10:49:00  Show Profile  Reply with Quote
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)

Singapore
17681 Posts

Posted - 08/04/2006 :  10:52:07  Show Profile  Reply with Quote
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



KH

Go to Top of Page

Srinika
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 08/04/2006 :  10:52:08  Show Profile  Reply with Quote
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)

Singapore
17681 Posts

Posted - 08/04/2006 :  10:53:01  Show Profile  Reply with Quote




KH

Go to Top of Page

chippyles
Yak Posting Veteran

68 Posts

Posted - 08/04/2006 :  11:11:33  Show Profile  Reply with Quote
thanks!!
Go to Top of Page

Srinika
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 08/04/2006 :  11:22:47  Show Profile  Reply with Quote
quote:
Originally posted by khtan





KH





One Second

Srinika
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000