Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
How To Use CASE Expression
How To Use CASE Expression? - MySQL FAQs - Introduction to SQL Basics
✍: FYIcenter.com
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, 4836👍, 0💬
Popular Posts:
What are secure and non-secure websites? A secure Website uses the Secure Socket Layer (SSL) protoco...
How To Set session.gc_divisor Properly? - PHP Script Tips - Understanding and Using Sessions As you ...
What is the benefit of using #define to declare a constant? Using the #define method of declaring a ...
What will be printed as the result of the operation below: main() { int a=0; if (a==0) printf("Cisco...
What will be printed as the result of the operation below: main() { int x=10, y=15; x = x++; y = ++y...