Contents IndexSaving statements as command files Chapter 14.  System Tables

User's Guide
   Part II. Tutorials
     Chapter 13. Command Files
      Command files with parameters

An example of a command file that would take a parameter is a command file to show the department an employee belongs to, providing the employee's name as a parameter.

To create a command file with parameters:

  1. Create a command file as listed below.

    The PARAMETERS command is used to give names to the parameters passed to a command file. In this case, we are giving the first parameter the name employee_name. The parameters are then used in the rest of the command file by enclosing them in braces ({}). Save the command file to emp_dept.sql.

         % This command file has one parameter
         parameters employee_name;
    
         select emp_lname, dept_name
         from employee
         NATURAL JOIN department
         where emp_lname = {employee_name};
    
  2. Run this command file by typing:
         READ emp_dept.sql
    
  3. You will be prompted for the employee_name. Enter the following value, including the single quotes:
         'Whitney'
    

    You should now see that the employee with surname Whitney is in the R&D department.

Parameters specifies on the READ command

Parameters can also be specified on the READ command. Try the following command:

     READ emp_dept.sql 'whitney'

In this case you have specified the parameter on the READ command, so ISQL will not prompt for it. ISQL will only prompt for parameters that are named in the PARAMETERS command but are not supplied on the READ command.

Contents IndexSaving statements as command files Chapter 14.  System Tables