Multiple conditions and values in MySQL query

The following query works fine

SELECT
SR_STU_ENROLL.NAME_L,
SR_STU_ENROLL.NAME_F,
SR_STU_ENROLL.CAMPUS_ID,
IF( SR_STU_ENROLL.GRD_LVL='12', '2013', '' ) AS gradYear,
SR_STU_ENROLL.STU_ID
FROM
SR_STU_ENROLL

How can I modify the if statement so that the grades and gradYears are all covered such as

if grd_lvl = 12 then output 2013
elseif grd_lvel =11 then output 2014

etc down to Kindergarten

Thank you!
LVL 2
smetterdAsked:
Who is Participating?
 
ralmadaConnect With a Mentor Commented:
USE CASE

SELECT
SR_STU_ENROLL.NAME_L,
SR_STU_ENROLL.NAME_F,
SR_STU_ENROLL.CAMPUS_ID,
CASE SR_STU_ENROLL.GRD_LVL
WHEN '12' then '2013'
WHEN '11' then '2014'
... and so on...
ELSE '' END AS gradYear,
SR_STU_ENROLL.STU_ID
FROM
SR_STU_ENROLL

Open in new window

http://dev.mysql.com/doc/refman/5.0/en/case.html
0
 
smetterdAuthor Commented:
Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.