Previous Topic: Database StorageNext Topic: Deciding How to Use CA Dataquery


Querying the Database

If you need to print a current list of your company's employees and their social security numbers, you can create a query to find the information in the database. Each item is kept in the PERSONNEL table. The names and social security numbers are stored on the database with other information, arranged by category.

SQL Example

You can retrieve the data you want and format it on the terminal screen or print it on a printer. The query that performs these tasks might look like this in SQL Mode:

 SELECT LAST_NAME, FIRST_NAME, SOCIAL_SECURITY
 FROM PERSONNEL
 ORDER BY LAST_NAME

SELECT, FROM, and ORDER BY are SQL keywords. SELECT tells CA Dataquery what kind of data to find and print. FROM tells the name of the table to search and ORDER BY sorts the rows alphabetically by name. Other keywords are available for creating more complex queries.

DQL Example

This is how the query looks in DQL Mode:

 FIND ALL PERSONNEL ROWS
 SORT BY LAST-NAME
 PRINT LAST-NAME
                        FIRST-NAME
                        SOCIAL-SECURITY

FIND, SORT, and PRINTG are DQL keywords. FIND tells which database table to read (PERSONNEL) and SORT arranges the rows alphabetically by name. PRINT specifies which values to display in columns on the report. Other keywords are available for qualifying the retrieved data, making calculations with it, and controlling how it appears in your report.

Results

The following report from either query appears as shown:

LAST-NAME                       FIRST-NAME SOCIAL-SECURITY
  ------------------------------  ---------  -------------
  SMITH                           JOHN       098765432
  THOMAS                          ARLENE     987654321
  VICTOR                          ROBERT     234567890
  WILSON                          JAMES      123456789

CA Dataquery provides a wide variety of common reporting capabilities. For instance, you can sort the information by state, city, zip code, or any category that seems logical. Or, you can retrieve only data for a certain state or city. You can rearrange the report columns or display the rows one at a time. You can even include data from additional database tables.