diff --git a/doc/sql.extensions/README.case b/doc/sql.extensions/README.case new file mode 100644 index 0000000000..e2a103e4a9 --- /dev/null +++ b/doc/sql.extensions/README.case @@ -0,0 +1,83 @@ +Function: + Allow the result of a column to be determined by a the results of a + case expression. + +Author: + Arno Brinkman + +Format: + + + ::= + + | + + ::= + NULLIF + | COALESCE { }... + + ::= + + | + + ::= + CASE + ... + [ ] + END + + ::= + CASE + ... + [ ] + END + + ::= WHEN THEN + + ::= WHEN THEN + + ::= + + ::= ELSE + + ::= + + | NULL + + ::= + + +Syntax Rules: + + +Examples: + +A) (simple) + SELECT + o.ID, + o.Description, + CASE o.Status + WHEN 1 THEN 'confirmed' + WHEN 2 THEN 'in production' + WHEN 3 THEN 'ready' + WHEN 4 THEN 'shipped' + ELSE 'unknown status ''' || o.Status || '''' + END + FROM + Orders o + +B) (searched) + SELECT + o.ID, + o.Description, + CASE + WHEN (o.Status IS NULL) THEN 'new' + WHEN (o.Status = 1) THEN 'confirmed' + WHEN (o.Status = 3) THEN 'in production' + WHEN (o.Status = 4) THEN 'ready' + WHEN (o.Status = 5) THEN 'shipped' + ELSE 'unknown status ''' || o.Status || '''' + END + FROM + Orders o + diff --git a/doc/sql.extensions/README.coalesce b/doc/sql.extensions/README.coalesce new file mode 100644 index 0000000000..ffbb3854e8 --- /dev/null +++ b/doc/sql.extensions/README.coalesce @@ -0,0 +1,38 @@ +Function: + Allow a column value to be calculated by a number of expressions, + the first expression returning a non NULL value is returned as the + column value + +Author: + Arno Brinkman + +Format: + + ::= + | COALESCE { }... + + +Syntax Rules: + 1) COALESCE (V1, V2) is equivalent to the following : + CASE WHEN V1 IS NOT NULL THEN V1 ELSE V2 END + 2) COALESCE (V1, V2,..., Vn), for n >= 3, is equivalent to the following + : + CASE WHEN V1 IS NOT NULL THEN V1 ELSE COALESCE (V2,...,Vn) END + + +Examples: +A) + + SELECT + PROJ_NAME AS Projectname, + COALESCE(e.FULL_NAME,'[> not assigned <]') AS Employeename + FROM + PROJECT p + LEFT JOIN EMPLOYEE e ON (e.EMP_NO = p.TEAM_LEADER) + +B) + SELECT + COALESCE(Phone,MobilePhone,'Unknown') AS "Phonenumber" + FROM + Relations + diff --git a/doc/sql.extensions/README.nullif b/doc/sql.extensions/README.nullif new file mode 100644 index 0000000000..465e378cb9 --- /dev/null +++ b/doc/sql.extensions/README.nullif @@ -0,0 +1,23 @@ +Function: + Speicify an alternative value for a column to return when it has a NULL + value. + +Author: + Arno Brinkman + +Format: + + ::= + NULLIF + + +Syntax Rules: + 1) NULLIF (V1, V2) is equivalent to the following : + CASE WHEN V1 = V2 THEN NULL ELSE V1 END + + +Examples: +A) + UPDATE PRODUCTS + SET STOCK = NULLIF(STOCK,0) +