SELECT clause

Specifies a select list for a query in a Query Statement or Database statement or passes values to the parameters of an external service in a Remote procedure statement.

Syntax

SELECT { expression [AS column | alias | parameter ] } [, ...]
Components

expression

An expression that evaluates to a value of the same data type as the corresponding destination column.

column

The name of a column in the query destination, as specified with the INSERT clause.

alias

An alias for a column as used in the EXECUTE STATEMENT DATABASE clause.

parameter

The name of a parameter used by the remote service.

Usage

The SELECT clause inside a Query statement, Database statement, or Remote Procedure statement specifies a select list of one or more items. Rows from the data sources listed in the FROM clause are passed to the SELECT clause after being filtered by the WHERE clause, if one is specified. The results of the expressions in the list are processed by other clauses (if any). If, after this processing, the CCL statement generates results, the results are handled differently, depending on the type of CCL statement in which they are used:

The following rules apply to the select list:

Automatic Schema Creation

Under certain circumstances the SELECT clause of a Query statement can be used to create a schema for a previously undefined data stream. The data stream can then be used in subsequent CCL statements in the current module. The automatic stream and schema creation can only be performed on a data stream that does not receive data from outside the current project.

The first Query statement that invokes the data stream must list the desired stream name in its INSERT clause, and then list the desired columns for the stream either in the INSERT clause, or in the SELECT clause. When the SELECT clause is used to define the stream's columns the following syntax is used:

SELECT { expression AS column } [, ...]

The use of the "select all" asterisk (*) is an exception to this syntactical requirement. When the first Query statement that included the data stream uses the "select all" asterisk (*), the column names for the destination stream are automatically inferred from the query's data source.

The stream schema and data types are then automatically created by Sybase CEP Engine. The data types for the columns of the automatic schema are determined by the data types of the data sources in the first Query statement that uses the stream as its destination.

Restrictions

See Also

Examples

Here is an example of the simplest SELECT clause, used by a Query statement that selects all the columns from its data source:

INSERT INTO OutStream
SELECT *
FROM Trades
WHERE Trades.Price = 100;

The following example includes a more complex Query statement SELECT clause:

INSERT INTO StepCompletionCounts
SELECT 
    COUNT(C.ScenarioID) AS TheCount,
    C.ScenarioID AS ScenarioID,
    C.StepID AS StepID
FROM 
    CompletedSteps AS C KEEP 10 SECONDS
GROUP BY
    C.ScenarioID, C.StepID
OUTPUT
    EVERY 10 SECONDS;

Here is an example of a SELECT clause in a Database statement:

EXECUTE STATEMENT DATABASE "MyDB"
  [[UPDATE Inventory 
    SET Inventory.Quantity = ?Quantity 
    WHERE Inventory.ItemID =?ID]]
SELECT
  StreamIn.ItemID AS ID, StreamIn.Quantity AS Quantity
FROM StreamIn;

Here is an example of a SELECT clause in a Remote Procedure statement:

EXECUTE REMOTE PROCEDURE "Search"
SELECT Name AS SearchString
FROM Clients;