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.
Author |
Topic |
Nader
Starting Member
41 Posts |
Posted - 2012-06-14 : 13:06:33
|
I am trying to get the percentage of students who lie in a particular category of achievement level according to their total percenatage the categories varies in number,naming, and valuesI had the following function because we had specifically 3 categories and exact percentage now those become dynamic how can I rewrite the following function (best performance) this will be called on an organizational levelCREATE FUNCTION [dbo].[fn_NewSLO_SectionSLO_Achieve_bySLO_Inline_try] (@SectionID INT,@FullyAchieved int, @PartiallyAchieved int) RETURNS TABLE AS RETURN (select count(case when T.Perc >= @FullyAchieved then T.StudentID end) as [FullyAchieved], count(case when (T.Perc < @FullyAchieved and T.Perc >=@partiallyAchieved) then T.StudentID end) as [PartiallyAchieved], count(case when T.Perc < @partiallyAchieved then T.StudentID end) as [FailedAchieved] from (SELECT e.StudentID as StudentID, sum ((isnull(AP.Points,0)*1.0/a.points)) as Perc FROM GradeBook.AssessmentPoint ap inner join gradebook.assessment a on ap.assessmentid=a.assessmentid)T);Now the level of achievement became dynamici.e. I do not have @fullyachieved,@partiallyAchieved percentageI have now a table Orgid, achievementlevelname, percentage1,Beginning,601, developing,701, meet expectations,801,exceedsexpectations,902, fullyachieved, 902,partiallyachieved,802,partiallyachieved,60Each organization will have a different number of achievementlevels and different percentageWhat is the best way to get the previous working with the new dynamic achievement levels and percentagesThanks |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-14 : 15:34:20
|
add table as a join to your current query and use field from table rather than variable @FullyAchieved ,@partiallyAchieved etc in case when. also you might have to add an extra filter on orgid------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|