I having a problem with figuring out how to get the problem below accomplished.Problem: I have a table full of entries which contain community service events and how many hours were recorded, these entries are also identified by a member id, year, and semester.I currently have a function which returns all of the events for a given year/semester combination.SELECT TOP 100 PERCENT commservice_stunum, commservice_year, commservice_semester, SUM(commservice_hours) AS commservice_hour_sumFROM dbo.commserviceGROUP BY commservice_stunum, commservice_year, commservice_semesterHAVING (commservice_year = @year) AND (commservice_semester = @semester)ORDER BY commservice_year DESC, commservice_semester, SUM(commservice_hours) DESC
This seems to be working fine for me on the website...However, on the website I need to know where each individual ranks compared to everyone else. So currently I am using a stored procedure (possibly incorrectly) to generate the same table as above, but with a rank.SELECT TOP 100 PERCENT a1.commservice_stunum, a1.commservice_year, a1.commservice_semester, a1.commservice_hour_sum,COUNT(a2.commservice_hour_sum) AS commservice_rankFROM dbo.commservice_hours_semester(@year, @semester) a1 CROSS JOIN dbo.commservice_hours_semester(@year, @semester) a2WHERE (a1.commservice_hour_sum <= a2.commservice_hour_sum) OR (a1.commservice_hour_sum = a2.commservice_hour_sum) AND (a1.commservice_hour_sum = a2.commservice_hour_sum)GROUP BY a1.commservice_stunum, a1.commservice_year, a1.commservice_semester, a1.commservice_hour_sumORDER BY a1.commservice_hour_sum DESC
Now, this seems to be working so far as well... but I can't reference this stored procedure inside another stored procedure, view, or function...Possible Solution:Would a function which returns a members rank given (id, semester, and year) be able to be used repeatedly within a stored procedure, and how would I write that function.Hell, possibly there is a better way to do all of this. I appreciate any support.Also, keep in mind I am referencing the information in the end via a website.Thanks In Advance,David