Creating queries

This section uses the Demo Getting Started project from the Demo Repository to create queries.

StepsCreating a simple query

To generate a simple query that retrieves all attributes from a table, use the PRODUCTS table.

  1. In the Navigator, select the Model tab, then click the table or view name. To search for a particular table or view name, press Ctrl+F.

  2. Drag the selected object to the Design window.

  3. To view the results of the generated query, select View | Generated Query or select the Generated Query tab.

StepsCreating a query using multiple tables

To generate a query that joins and retrieves information from two tables, use the PRODUCTS and SALES tables.

  1. Drag the PRODUCTS table from the Navigator to the Design window.

  2. Drag the SALES table from the Navigator to the Design window.

  3. Create a join between the tables by linking the PR_ID fields of both tables. If you want Query Designer to automatically create joins between identically named attributes within tables or views:

    1. Select File | Preferences from the main Sybase ETL Development window.

    2. Select Workbench | Query Designer, then select Create joins automatically. See “Customizing preferences”.

  4. To view join attribute details, click the Join tab in the Query Designer window.

StepsModifying the default settings of a join

A join between two tables is indicated by a line that connects the joining fields. The line is labeled with a join operator, which, by default, is called Equi Join.

  1. Right-click the line connecting the two joining fields.

  2. Select Modify.

  3. Select a join type.

StepsModifying the sort order of joins

  1. In the Join tab, right-click a row and select:

    • Move to start

    • Move up

    • Move down

    • Move to end

  2. To revert to the default state of the join at any point, right-click a row and select Sort joins to default order.

StepsAdding one or more attributes to the select clause

  1. Drag the PRODUCTS and SALES tables to the Design window, if they are not there already.

  2. To add a single attribute, right-click the attribute you want to add, and select Add Items to Selection. To add more than one attribute, hold down the Ctrl key while you select the attributes you want to add.

    Alternatively, click the PRODUCTS and SALES tabs in the Query Definition pane and select the attributes you want to add to the select clause. To search for an attribute, click the Search icon and provide your search criteria.

    You can use an asterisk (*) as a wildcard to search for any number of unknown characters. For example:

    • If your attribute is an integer datatype, your search criteria can be one of these:

      int, int*, i*ger
      
    • If your attribute name contains “PROD” and has “CD” at the end, your search criteria can be:

      *PROD*CD
      

StepsAdding all attributes of a selected table to the select clause

  1. In the Query tab, click the header of the table.

  2. Right-click and select Add Items to Select.

StepsViewing attribute details and generated query

  1. To view a query generated by the Query Designer, select View | Generated Query, or select the Generated Query tab.

  2. Click the appropriate tabs to view the attribute details.

StepsAdding functions to the select attribute

  1. In the Select tab, right-click the attribute to which you want to add functions.

  2. Choose the functions to add.

NoteTo enforce appropriate and reliable attribute names for viewing data and port structures, define alias names for all attributes to which functions have been applied. See Adding alias names to selected attributes and “Use column aliases when entering queries”.

StepsAdding alias names to selected attributes

  1. In the Select tab, enter a name in the Alias column to enforce an output column name used in Data Viewer and associated port structure.