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 2005 Forums
 Transact-SQL (2005)
 Why is this divide so difficult?

Author  Topic 

gangelo
Starting Member

6 Posts

Posted - 2009-07-27 : 16:32:19
All I want to do is compute the percent of answered questions:

select (5/10)*100 as [Percent]

and 0 is returned, what am I missing here?

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-27 : 16:52:57
You are doing integer division.. try: select (5.0/10)* 100 as [Percent]
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-27 : 16:57:41
If 5 and 10 are columns are variables, change 100 to 100.0



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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-28 : 02:24:04
Here is the reason
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx

Madhivanan

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

gangelo
Starting Member

6 Posts

Posted - 2009-07-28 : 09:05:25
Thank you all, these solved it
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-28 : 09:13:36
quote:
Originally posted by Peso

If 5 and 10 are columns are variables, change 100 to 100.0



N 56°04'39.26"
E 12°55'05.63"



In that case one of the variables should be multiplied by 1.0


select (5/10)*100.0 as [Percent]

select (1.0*5/10)*100 as [Percent]

Madhivanan

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

- Advertisement -