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)
 Calculating Percentage

Author  Topic 

harlingtonthewizard
Constraint Violating Yak Guru

352 Posts

Posted - 2008-10-08 : 00:06:27
I have the following, which returns 33.33' mathematically however this query returns 0.0. Just think of it as two numbers and I need percentage:)

SELECT EventswithComments / Total * 100

(In my test query this would be 4/12*100)

EventswithComments and Total are calculated with:

SELECT Count(*)As Total, Count (OverLapSum.EventID) As EventswithComments

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-08 : 00:14:45
SELECT EventswithComments * 100.0/ Total
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-08 : 00:16:11
reason is this
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx
Go to Top of Page
   

- Advertisement -