17. System Commands for the Forms-based Tools : report Command--Run a Report : Passing Parameters on the Command Line : Passing String and Date Variables
 
Share this page                  
Passing String and Date Variables
The report specification must enclose the string and date variables, $dname and $ddate, in quotes that are appropriate for your query language (in this case, single quotes for SQL), as shown in the following example:
.declare  dname = varchar(20),
          ddate = date
.query select firstname, lastname, deptid from employees
      where deptname = '$dname' and hiredate >= '$ddate'
The previous example retrieves data for employees in the named department, $dname, who were hired on or after a specified date, $ddate.
If the variable is quoted appropriately for your query language (single quotes for SQL or double quotes for QUEL) in the report specification, use the following syntax for specifying a string or date value on the report command line:
report dbname tablename (variablename='value')
Each string or date value must be enclosed in single quotes to identify it to Report‑Writer as a string. Report‑Writer strips off these quotes before assigning the value to the variable in the query. Additionally, enclose the entire variablename=value clause in parentheses ( ). If it contains any characters treated specially by your operating system (such as parentheses in Windows NT and UNIX or slashes in VMS), the parenthetical clause must be enclosed within double quotes to pass it through the operating system.
For example:
report personnel emp "(dname='BL', ddate='01/01/98')"
If the report specification omits the query language‑specific quotes around the variable (for example, where deptname = $dname instead of where deptname = '$dname'), these quotes must be supplied to the query. To do so, include them in the string or date value on the command line within the single quotes required to identify the string to Report‑Writer. You must dereference the embedded single quotes required by SQL. To dereference single quotes within a single‑quoted string you double them (''). Additionally, if the parenthetical clause contains characters special to your operating system, enclose the entire parameter within double quotes. For example:
report personnel emp "(dname='''BL''',
    ddate='''01/01/98''')"
Note for QUEL Users
The report specification must enclose the string and date variables, $dname and $ddate, in double quotes for QUEL, as shown in the following example:
.declare    dname = varchar(20),
            ddate = date
.query
range of e is emp
retrieve     (e.firstname,e.lastname,e.deptid)
      where  e.deptname = "$dname" and 
             e.hiredate >= "$ddate"
This example retrieves data for employees in the named department, $dname, who were hired on or after a specified date, $ddate.
If the report specification omits the query language‑specific quotes around the variable (for example, where e.deptname = $dname as opposed to where e.deptname = "$dname"), these quotes must be supplied to the query by including them within the string or date value on the command line, inside the single quotes that identify the string to Report‑Writer. Additionally, if the parenthetical clause contains characters special to your operating system, enclose the entire parameter within double quotes and escape any double quotes within the parameter according to the rules for your operating system.
Windows: In Windows, you escape double quotes by preceding them with a backslash (\). For example:
report personnel emp "(dname='\"BL\"',
ddate='\"01/01/91\"')"
UNIX: In UNIX, you escape double quotes by preceding them with a backslash (\). For example:
report personnel emp "(dname='\"BL\"',
ddate='\"01/01/91\"')"
VMS: In VMS, you escape double quotes by preceding them with another double quote. For example:
report personnel emp "(dname='""BL""',
ddate='""01/01/91""')"