-- 3. Create a variable to store a numeric grade
-- Write a CASE statement that uses the variable to calculate a
letter grade
-- If the numeric grade is above 100 or below 0, return "Invalid
grade"
-- A = 90-100, B = 80-89, C = 70-79, D = 60-69, F = 0-59
-- Hint: SELECT doesn't always require a FROM clause
Solution:
DECLARE @numericGrade int;
SET @numericGrade= 80;
SELECT
CASE
WHEN @numericGrade >= 90 AND @numericGrade<=100 THEN 'A'
WHEN @numericGrade>= 80 AND @numericGrade<90 THEN 'B'
WHEN @numericGrade>=70AND @numericGrade<80 THEN 'C'
WHEN @numericGrade>=60 AND @numericGrade<70 THEN 'D'
ELSE 'Invalid Grade'
END
Note: Have done it in MSSQL , as no language is asked in specific in the question
Output:
Get Answers For Free
Most questions answered within 1 hours.