WHERE Clause

The WHERE clause imposes conditions on the SELECT statement. Put another way, it restricts the number of rows returned, based on the indicated criteria.

Syntax

SELECT <field-name-1>[, <field-name-2>] ...
FROM tablename
WHERE condition

Example

EXEC SQL
    SELECT
        C_FIRST_NAME, C_LAST_NAME,
        TO_CHAR, C_INFO
    INTO 
        :C-FIRST-NAME, :C-LAST-NAME, :C-BIRTHDAY, :C-INFO
    FROM CUSTOMER
    WHERE C_NUMBER = :C-NUMBER
END-EXEC.

Using the example from the previous topic, the program to place values for these fields INTO the corresponding COBOL variables, which are C-FIRST-NAME, C-LAST-NAME, etc. The semicolon in the code indicates that these are COBOL (host) variables. See an SQL text for more information on conditions and operators supported by SQL.