我有一个学生考试的GradeConversionCriteria表,它有三列:
FromNumber
ToNumber
Grade
我想创建一个用户定义的函数,当我输入marksobtained和totalmarks
时将返回等级如果一个学生在50分中得到45分,我想要归还他所取得的成绩(A,B,C等)。
答案 0 :(得分:1)
您希望函数具有类似此查询的内容:
create function ConvertGrades (
@marksobtained int,
@totalmarks int
) returns char(1) as
select
grade
from
gradeconversioncriteria
where
@marksobtained/@totalmarks between fromnumber and tonumber
然后你会做这样的事情来获得成绩:
select
s.student_id,
s.student_name,
t.marksobtained,
t.totalmarks,
dbo.ConvertGrades(t.marksobtained, t.totalmarks) as grade_letter
from
tests t
inner join students s on
t.student_id = s.student_id