CL Command Reference - STRQMQRY
CL Command List > STRQMQRY Reference
Description:
The Start Query Management Query (STRQMQRY) command is used to run a query.
To use this command, you must first identify the query that is to be processed. The query is any single Structured Query Language (SQL) statement in a QMQRY object. The SQL statement can also be taken from a query definition (QRYDFN) object when a QMQRY object does not exist.
You can show the output on the display, print it, or store it in a database file.
If the SQL statement inside the query does not create an answer-set, then no report or output file is created. This happens if the SQL statement inside a query is not valid or the SQL statement is not a SELECT clause.
If the query contains substitution variables, the SETVAR parameter can be used to set the variables for the query. If prompting is enabled, query management asks the user to provide a value for each variable that was not set.
Examples:
Example 1: Displaying Query Output
STRQMQRY QMQRY(MYLIB/MYQRY) QMFORM(FORM1)
This command runs query management query MYQRY located in library MYLIB. The library list is searched for form FORM1, which is used for the output sent to the display.
Example 2: Taking Information From Either QMQRY or QRYDFN
STRQMQRY QMQRY(MYLIB/MYQRY) QMFORM(FORM1) ALWQRYDFN(*YES)
This command runs query management query (QMQRY) MYQRY located in library MYLIB. If QMQRY object MYQRY is not found in library MYLIB, the information is taken from query definition (QRYDFN) MYQRY located in library MYLIB. The library list is searched for query management form FORM1 whose information is used to format the output. If QMFORM object FORM1 is not found in the library list, the library list is searched for QRYDFN FORM1, and that information is used to format the output shown on the display.
Example 3: Printing Query Output
STRQMQRY QMQRY(MYLIB/QUERY1) OUTTYPE(*PRINTER)
This command runs query QUERY1 located in library MYLIB. The report is formatted and printed on the printer specified in the printer file associated with the query session.
Example 4: Sending Output to an Existing File
STRQMQRY QMQRY(*CURLIB/MYQRY) OUTPUT(*OUTFILE) OUTFILE(MYTAB) OUTMBR(*FIRST *ADD)
This command runs the query named MYQRY located in the current library for the user¡¯s job. The selected data records are added to the previously created table named MYTAB in collection MYCOL.
Example 5: Running a Query Containing Substitution Variables
STRQMQRY QMQRY(MYQUERY)
SETVAR((VAR1 ¡¯select * from mytable¡¯)
(VAR2 ¡¯where salary > 15000¡¯))
This command runs query MYQUERY, which contains only substitution variables, &VAR1 and &VAR2. These two variables contain the entire structured query language (SQL) statement.
Example 6: Changing a Variable
STRQMQRY QMQRY(QRYNAME) SETVAR((LASTNAME ¡¯¡¯¡¯Smith¡¯¡¯¡¯))
This command runs query QRYNAME, setting the variable LASTNAME to the value, ¡¯Smith¡¯.