CCL Expressions in the WHERE Clause

The WHERE clause uses expressions to restrict the data captured by the SELECT clause.

Consider the following change to the previous query:

INSERT INTO TradeValues(id, tradevalue) 
SELECT tradeid, volume*price 
FROM StockTrades 
WHERE symbol LIKE 'A%' AND (volume*price) > 50000.00

The WHERE clause has a complex expression which filters rows for symbols that start with the letter 'A', but only if the total trade value is also greater than $50,000. The LIKE comparison operator is used to support "wildcard" comparisons for strings. The percent sign (%) in the literal 'A%' means to match any character values after the initial letter 'A'. In the small subset of data in the example, this would only find the symbol 'AAPL'.

A WHERE clause expression may refer to columns that are not included in the select list of the SELECT clause as shown in this example (symbol), although the columns must still be present in the data sources listed in the FROM clause.

Also note the use of the parentheses to group the multiplication operation. Although this isn't strictly needed in this example, using parentheses helps to make it clear to anyone reading the query what calculations are actually being executed.

Here is an example of what the input and output streams would look like for this query:



The use of expressions in the WHERE clause is somewhat more restricted than their use in the SELECT clause. The WHERE clause must always evaluate to a value of TRUE or FALSE. This is usually accomplished using comparison and logical operator expressions, although it is possible for other expressions, even those without a comparison or logical operator, to evaluate to TRUE or FALSE.


Created March 8, 2010. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com