0

I have a GradeConversionCriteria table for Student Exam that has three columns:

FromNumber 
ToNumber 
Grade

I want to make a user defined function that will return the Grade when I input marksobtained and totalmarks

If a student gets 45 marks out of 50 I want to return the grade(A,B,C etc.) he achieved.

0

1 Answer 1

1

You want something like this query for your function:

create function ConvertGrades (
    @marksobtained int,
    @totalmarks int
) returns char(1) as
select
    grade
from
    gradeconversioncriteria
where
    @marksobtained/@totalmarks between fromnumber and tonumber

Then you would just do something like this to get the grades:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.