This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
dev:sql:functions:case [2009/12/04 22:23] tdo |
dev:sql:functions:case [2012/10/26 14:28] (current) |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| <html><div align="center"><span style="color:red">DRAFT</span></div></html> | <html><div align="center"><span style="color:red">DRAFT</span></div></html> | ||
| ====== Omnidex SQL Function: CASE ====== | ====== Omnidex SQL Function: CASE ====== | ||
| + | {{page>:sql_bar&nofooter&noeditbtn}} | ||
| ===== Description ===== | ===== Description ===== | ||
| The CASE function handles simple IF - THEN - ELSE logic at a select-item level. The WHEN conditions are evaluated in order until a condition proves TRUE, at which point the THEN expression is executed. All of the THEN expressions in a CASE statement must be of the same data type: numeric, character, or date. | The CASE function handles simple IF - THEN - ELSE logic at a select-item level. The WHEN conditions are evaluated in order until a condition proves TRUE, at which point the THEN expression is executed. All of the THEN expressions in a CASE statement must be of the same data type: numeric, character, or date. | ||
| Line 19: | Line 20: | ||
| ===== Example ===== | ===== Example ===== | ||
| - | + | ==== Example 1 Condition Expression ==== | |
| - | ==== Example 1 ==== | + | <code SQL> |
| CASE | CASE | ||
| WHEN PRODUCTS.CATEGORY < 30 THEN 'Furniture' | WHEN PRODUCTS.CATEGORY < 30 THEN 'Furniture' | ||
| Line 27: | Line 28: | ||
| ELSE 'Office Supplies' | ELSE 'Office Supplies' | ||
| END | END | ||
| - | + | </code> | |
| - | ==== Example 2 ==== | + | ==== Example 2 Scalar Expression ==== |
| + | <code SQL> | ||
| CASE DATES.MO | CASE DATES.MO | ||
| WHEN 'Jan' THEN 1 | WHEN 'Jan' THEN 1 | ||
| Line 36: | Line 38: | ||
| ELSE 0 | ELSE 0 | ||
| END | END | ||
| - | + | </code> | |
| - | ==== Example 3 ==== | + | ==== Example 3 Select Statement with Conditional Expression ==== |
| <code SQL> | <code SQL> | ||
| Line 54: | Line 56: | ||
| order by state | order by state | ||
| </code> | </code> | ||
| - | ==== Example 4 ==== | + | ==== Example 4 Select Statement with Scalar Expression ==== |
| <code SQL> | <code SQL> | ||
| select company, contact, | select company, contact, | ||