SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Case Statements

  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    how hard did you try to look up the actual syntax and learn from the examples?
    Code:
    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
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,107
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Actually i haven't see good example for this kind of problem

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by jemz View Post
    Actually i haven't see good example for this kind of problem
    here you go --> http://www.devshed.com/c/a/MySQL/Adv...g-concluded/2/
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •