12. Report-Writer Statements : Report Setup Statements : .Query Statement for QUEL Users : Examples
 
Share this page                  
Examples
1. You set up the query as:
.query
        range of e is emp
        retrieve (e.all)
                where e.salary > $sal
                and e.dept = "$dept"
You invoke the command:
report mydb myrep (sal = 50000, dept = 'toy')
Enclose toy within single quotes to identify it to Report-Writer as a string. Report-Writer strips off these quotes before passing it to the query.
Note:  If your operating system requires it, enclose the parenthetical clause within double quotes:
report mydb myrep "(sal = 50000, dept = 'toy')"
Report-Writer executes the following query:
range of e is emp
retrieve (e.all) where e.salary > 50000
        and e.dept = "toy"
2. Consider a table called, account, with columns including custno, custname, checking, and savings. You have separate fields for checking and savings accounts on one row, because most customers have both a savings and a checking account with the bank. To write one report specification that prints either the savings or checking account balances with a single query, you can code a .query statement similar to the following:
.declare account_type = c10 with prompt
        "Please enter the type of account:"
.quel
        range of a is account
        retrieve(a.custno, a.custname, val=a.$account_type)
You can invoke the query with the command:
report otherdb repname
At execution, Report-Writer issues the following prompt:
Please enter the type of account:
Suppose you respond with:
savings
The following query would be executed:
range of a is account
retrieve(a.custno, a.custname, val=a.savings)
To print the value of the savings column, use:
.println val
This query selects values from the database savings column, not the string constant, savings.