How To Use CASE Expression
How To Use CASE Expression? - MySQL FAQs - Introduction to SQL Basics
There are 2 ways to use the CASE expression. The first way is to return one of the predefined values based on the comparison of a given value to a list of target values. The second way is to return one of the predefined values based on a list of conditions. Here is the syntax of both types of CASE expressions:
CASE value WHEN target_value THEN result WHEN target_value THEN result WHEN target_value THEN result ... ELSE result END CASE WHEN condition THEN result WHEN condition THEN result WHEN condition THEN result ... ELSE result END
The tutorial exercise below gives two good examples:
SELECT CASE 'Sun' WHEN 'Mon' THEN 'Open' WHEN "Fri" THEN "Open" ELSE 'Closed' END FROM DUAL; Closed SELECT CASE WHEN HOUR(CURRENT_TIME())<9 THEN 'Closed' WHEN HOUR(CURRENT_TIME())>17 THEN 'Closed' ELSE 'Open' END FROM DUAL; Closed
2007-05-11, 4564👍, 0💬
1. What is normalization. 2. Difference between procedure and functions. 3. Oracle 9i Vs 10g. 4. how...
Which are the various programming approaches for WCF?
Can include files be nested? The answer is yes. Include files can be nested any number of times. As ...
Which is the best place to store ConnectionString in Dot Net Projects? I am about to deploy my first...
If we have two version of same assembly in GAC how do we make a choice ? OK first let’s try to under...