SQL III-8

  1. Using advanced SQL value expressions
    • ? Using the CASE conditional expressions
    • ? Converting a data item from one data type to another
    • ? Saving data entry time by using row value expressions
  2. CASE conditional expression
    SQL has a CASE statement and a CASE expression. A CASE expression is only part of a statement — not a statement in its own right. In SQL, you can place a CASE expression almost anywhere a value is legal. At run time, a CASE expression evaluates to a value. SQL’s CASE statement doesn’t evaluate to a value; rather, it executes a block of statements.

    You can use the CASE expression in the following two ways:

    • ? Use the expression with search conditions. CASE searches for rows in a table where specified conditions are True. If CASE finds a search condition to be True for a table row, the statement containing the CASE expression
    • makes a specified change to that row.

    ? Use the expression to compare a table field to a specified value. The outcome of the statement containing the CASE expression depends on which of several specified values in the table field is equal to each table row.
  3. using CASE with search conditions
  4. CASE
    • WHEN condition1 THEN result1
    • WHEN condition2 THEN result2
    • ...
    • WHEN conditionn THEN resultn
    • ELSE resultx
    • END
  5. updating values based on a condition
    Image Upload 2
  6. avoiding conditions that cause error
    Image Upload 4
  7. using case with values
    Image Upload 6
  8. a special CASE- NULLIF
    • UPDATE FLIGHT
    • SET RefuelStop = CASE
    • WHEN RefuelStop = ‘San Jose’
    • THEN NULL
    • ELSE RefuelStop
    • END ;

    • UPDATE FLIGHT
    • SET RefuelStop = NULLIF(RefuelStop, ‘San Jose’) ;
Author
dau108
ID
145532
Card Set
SQL III-8
Description
SQL III-8
Updated