Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why would a SQL divide in a select statement always return 0?

Status
Not open for further replies.

Dom71555

IS-IT--Management
Feb 6, 2005
47
US
I am trying to have a column in a table contain a % of students that recieved a certain grade for a particular standard.
This is a sample of the table I am querying..

Table Name #elementary_score_final_aggregate

school varchar(8),
gradeLevel varchar(8),
curriculumName varchar(50),
standardName varchar(75),
endyear varchar(5),
termName varchar(20),
gradeCount int,
achievementLevel varchar(2),
rostercount int)

Sample of Values in the table..
0004 01 Language Arts Reading 2009 T2 7 1 117
0004 01 Language Arts Reading 2009 T2 33 2 117
0004 01 Language Arts Reading 2009 T2 52 3 117
0004 01 Language Arts Reading 2009 T2 23 4 117

Here is the query that I have the problem with..

select school,
gradelevel,
curriculumName,
standardName,
endyear,
termName,
gradecount,
achievementlevel,
achievementPercent = ((gradecount/rostercount)*100), rostercount
from #elementary_score_final_aggregate
group by school,gradelevel,curriculumName, standardName, endyear, termName, gradecount, achievementlevel, rostercount

Result..
achievementResult laways returns 0


Thank you for your help.
 
Int divided by Int equals Int. Try this

achievementPercent = ((gradecount/CONVERT(DECIMAL(18,2), rostercount))*100)
 
Thank you RiverGuy. It worked perfectly!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top