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)
 divide

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2007-09-13 : 10:19:11
Hi,
How can I get this query to return 0.1 ?
select 10/100

it currently returns 0

Thanks

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2007-09-13 : 10:24:18
select 10/100.0, 10/cast(100 as smallmoney)

PS: If anyone is interested in a SQL Server job in Connecticut with excellent pay send me a resume to ValterBorges@msn.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-09-13 : 10:24:34
By NOT using integer division

select 10.0 / 100.0

select 1.0 * 10 / 100


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-09-13 : 10:46:07
It is becuase result becomes integer when both numerator and denominator are integers. You need to force one operand to be decimal

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -