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
 SQL Server Development (2000)
 Get the Percentage

Author  Topic 

guptaalok12
Starting Member

5 Posts

Posted - 2008-09-24 : 03:22:49
MaxMarks MarksObtained
100 40
150 50
75 34

this is my table(stu) ,i want the percentage of total marks
select sum(MarksObtained)/Sum(MaxMarks) * 100 from Stu
but it is not working........
Pls help Thanks

alokgupta

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-24 : 03:30:46
quote:
Originally posted by guptaalok12

MaxMarks MarksObtained
100 40
150 50
75 34

this is my table(stu) ,i want the percentage of total marks
select sum(MarksObtained)/Sum(MaxMarks) * 100.0 from Stu
but it is not working........
Pls help Thanks

alokgupta


since You're dividing ineteger value by another integer value, you'll get only the integer result. So multiply by 100.0 to cast it to float implicitly and then you'll get correct value.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-09-24 : 03:56:48
select 100.0 * sum(MarksObtained) / Sum(MaxMarks) from Stu


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

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-24 : 04:56:55
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
   

- Advertisement -