From: SQL Learner on 7 Feb 2010 20:08 Hi All, If I have the following one-column table: Grade 80 100 90 60 50 90 I want to add a new column (in the result, not in the physical table) called "Letter_Grade" using the following convertion method: 50 = F 60 = D 70 = C 80 = B 90 and 100 = A How can I do it? You may provide more than one solutions. Thanks. SQL Learner
From: Plamen Ratchev on 7 Feb 2010 21:19 You can use a CASE expression: SELECT grade, CASE WHEN grade = 50 THEN 'F' WHEN grade = 60 THEN 'D' WHEN grade = 70 THEN 'C' WHEN grade = 80 THEN 'B' WHEN grade IN (90, 100) THEN 'A' END AS letter_grade FROM Grades; -- Plamen Ratchev http://www.SQLStudio.com
From: SQL Learner on 7 Feb 2010 21:31 Plamen, Thank you so much again! That works. SQL Learner
From: Malcolm Dew-Jones on 7 Feb 2010 23:54 SQL Learner (excelmodeling(a)gmail.com) wrote: : Plamen, : Thank you so much again! That works. : SQL Learner Are you sure you correctly stated the original problem? I also wonder if there was a reason the original values were stored in a table.
From: RRR on 8 Feb 2010 10:47 > > Are you sure you correctly stated the original problem? I also wonder if > there was a reason the original values were stored in a table. I, too, was concerned about that. If this were to be used as a means of transforming any score to the correct grade, then the CASE approach shown would have to specify all possible expected score values. If that is the case, then the CASE statement should be more generalized so as to map a range of scores to a letter grade.
|
Next
|
Last
Pages: 1 2 Prev: Jet uses Yellowfin for Location Intelligence Next: DTS or Stored Procedure? |