Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Sql Mysql-example MySQL Case

Related Tutorials


 
 

Share on Google+Share on Google+

MySQL Case

Advertisement
MySQL Case: If you want to implement a complex conditional construction then you can use MySQL case statement. It performs the work as programming type.

MySQL Case

     

This example illustrates how to use case statement in MySQL database.

MySQL Case: If you want to implement a complex conditional construction then you can use MySQL case statement. It performs the work as programming type.  The CASE statement  is used with two other keywords "WHEN" and "THEN". If the column data is matched with the "WHEN" data then it takes the corresponding "THEN" data. If no data is matched then the "ELSE" data is taken.

 

 

 

 

Table: employeeDetails

To use the mysql case:

SELECT daysName, CASE daysName 
  WHEN "Sunday" THEN "Holiday" 
  WHEN "Monday" THEN "Working Day" 
  WHEN "Tuesday" THEN "Working Day" 
  WHEN "Wednesday" THEN "Working Day" 
  WHEN "Thrusday" THEN "Working Day" 
  WHEN "Friday" THEN "Working Day" 
  WHEN "Saturday" THEN "Holiday" 
   ELSE "Illegal Argument" 
END AS "Status" 
from employeeDetails;

Output:

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: January 20, 2009

Related Tutorials

Discuss: MySQL Case  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Satya
May 21, 2012
Mysql CASE statement

Hi, I have a problem while using MYSQL case Statement In SSRS 2008 R2. My scenario is: I am passing hardcoded values in parameter dropdown (County, State). And i am using another parameter depending on If i select the "county" in by dropdown, I need get all county values in dropdown or if select state i need to get all state values in my dropdown. What i am writing in my code select case when parameter.geolevl.value = "County" then "select distinct county_name from county" when parameter.geolevl.value = "State" then "select distinct state from county" is this code will work in SSRS 2008 R2 Please help me with this Issue
DMCA.com