Case Statements

Hi, can i ask some help,How can i do this in my sql query to have Case statement?
Example in my employee table i want to have case statement on my empno.

select * from employee
case
when empno = “000070” then firstname = “Jack”
when empno = “000050” then firstnmae = “Stellar”
when empno = “000030” then firstname = “Sheek”
else firstname = “jemz”
end

can you help me please i am confuse in my querry.

Thank you in advance.:slight_smile:

how hard did you try to look up the actual syntax and learn from the examples?


CASE WHEN empno = '000070' THEN 'Jack'
     WHEN empno = '000050' THEN 'Stellar'
     WHEN empno = '000030' THEN 'Sheek'
     ELSE 'jemz'
 END AS firstname

also, the CASE expression is not allowed to some after the FROM clause

Hi,

Actually i haven’t see good example for this kind of problem :slight_smile:

here you go –> http://www.devshed.com/c/a/MySQL/Advanced-Query-Writing-concluded/2/