Previous Topic

Next Topic

Book Contents

Book Index

Scripting - SetParm

This function names a User-Defined Parameter and sets a value for it.


--aqt setparm,parm=schema,value=SYSCAT

--aqt output,file=batch_sample.csv,type=csv,filemode=append

select * from syscat.tables where tabschema ='$schema';

Setting a parameter to a result of a query

You can set the parm to a value returned by a query. Example:

--aqt setparm,parm=yesterday,value=(select current date - 1 day from sysibm.sysdummy1)

If the query returns multiple rows/columns, only the first column of the first row will be used.

Setting a parameter to a value returned by a prior query or stored procedure

You can set a parameter to a value returned by a query, or to an OUT parameter from a stored procedure. This can be useful if you are passing data between a series of SQL statements.

Coding value=$result(3) will set the parm to the 3rd column of the last query run. If the query returned more than one row, the value will come from the last row. If there was no previous query, or the query returned zero rows, the results can be unpredictable.

Coding value=$parm(2) will set the parm to 2nd query parameter (as specified with a Parm function). You would typically use this when the Parm function has specified an Out or Inout parameter, and you have run a stored procedure.

You can embed these functions inside other characters. Example: value=EMP$result(1)00 will return EMPSMITH00 if $result(1) is SMITH.

Setting a parameter to a list of values from an external source

You can set a parameter to a list of values contained in a file (either a csv file or Excel file) or a from a query.

Thiis is described in Scripting - SetParm - $list

Setting a parameter to an Environment Variable

You can set a parameter to an environment variable by coding:


In this example, CUSTCODE is an environment variable. When running batch-mode AQT, you can set this in the batch file that invokes AQT.

Setting a parameter to a System value

You can set a parameter Value to one of the following system values.


The current date


The current date in the format specified by dformat.

Has been superseded by <date:format(dformat)>


The current time in hh:mm:ss format


The current timestamp in yyyy-mm-dd hh:mm:ss format


This is only used when running AQT in batch. It gives the name of the script that is being run.

For instance if your *.bat file has: aqt c:\aqt\Customer_Report.sql then <scriptname> returns Customer_Report.


Returns the script directory. In the above example, <scriptpath> wiill return c:\aqt

Additional options for <date>

You can apply a number of functions to <date> to generate a related date. These are specified as:


There is no limit on how many functions can be used.

The functions that can be specified are as follows:


Start of the date period.

datetype is one of h (hour), d (day), w (week), m (month) or y (year).

The start of a week is the Sunday.

Example: startof(m) will be the first day of the month.


End of the date period. dateperiod is as above.

The end of a week is Saturday.

Example: endof(m) will be the last day of the month.


Adds to the date.

  • datetype is as above
  • number is the number of these to add

Example: add(m,1) adds a month to the date


Similar to add, however the number is subtracted.


Specifies how the date is to be formatted. If this is not specified yyyy-MM-dd will be used.

Note that MM is month, mm is minute.

For hour, use HH (24-hour) rather than hh (12-hour)


<date> gives 2021-08-30

<date:format(MMddyyyy)> gives 08302021

<date:format(HHmmss)> gives 204515.

<date:format(yyyyMMddHHmmss)> gives 20210830204515


Converts the datestring to a date.


Converts a datestring to a date, specifying the format of the datestring.

Example 1


This returns the current date in yyyy-MM-dd format (2021-10-21)

Example 2



Example 3

This shows the use of two connected parms, plus the use of the from function.

--aqt queryparm,parm=sdate,desc=Start Date,select=date

--aqt setparm,parm=edate,value=<date:from($sdate,yyyy-MM-dd):endof(m)>

select * from sales where sale_date between '$sdate' and '$edate'

In this:

Date and Time

<date> includes both the current date and time.

Setting a Parameter to an AQT Option

You can set the parameter to an AQT option with:


Any AQT option can be used, however the most useful ones are likely to be exportdir (the default export directory) and querydir (the query directory). Examples:

Advanced Query Tool
© 2023 Cardett Associates Ltd. All rights reserved.