Creating a Query

 

You can write a new SQL query with DB2 Web Query Tool. You can then save or run the query. You can also create a query that calls stored procedures.

Fields and Controls for the Edit Query screen

To create a new SQL query:

1.         In the desired connection branch of the DB2 Web Query Tool navigation tree, click SQL Queries.

The Queries menu appears.

2.         From the drop-down menu, select New.

The Edit Query page opens.

3.         In the Enter an SQL Statement field, type an SQL statement. You can include multiple statements in a single query, as well as comments and variables. You can also use lookup variables, which refer to other queries or results to produce a drop-down menu of substitution values.

DB2 Web Query Tool supports the following comment formats: --comment, //comment.

DB2 Web Query Tool supports the following variable formats: [variable], :variable, ?, and &variable.

Tip:     Use a semi colon to separate multiple statements in a query.

4.         Click Next. The Query Options screen opens.

5.         In the Result Name field, type the name of the results set.

Note:     DB2 Web Query Tool provides a default results set name. You can replace this name with one that you prefer.

6.         In the Max Rows field, type the maximum number of rows to return in the results set.

Note:     To return all rows to the results set, enter "0" in the Max Rows field.

7.         In the Timeout field, type a time-out limit.

8.         From the Action drop down list, select an action that specifies how LOBs will be retrieved from the database. The options are as follows:

·          Select Omit to omit the LOB from the result set.

·          Select Retrieve to have LOBs retrievable from the results set. When you select Retrieve, LOBs will appear as links in the results set. You can click the link to view a particular LOB and DB2 Web Query will retrieve that LOB for you from the DB2 table and show it in a viewer.

·          Select Embed to have the LOB data embedded in the results set

9.         In the Limit field, type the maximum size (in k) of a LOB that will be available in the results set. Any LOB that is larger than the specified limit will not be embedded.

10.      From the Type drop down list, specify the file type (extension) of LOBS that will be returned by your query.

·          Select None to have a MIME type of APPLICATION/OCTECT returned to the client.

·          Select Static to indicate that all LOB data in the table is of the same type and that the same extension should be applied to all LOBs. Specify the extension to apply to each LOB in the Ext/Column field.

·          Select Column to indicate LOB data is of different types and that the type of the LOB data is stored in a column that is referenced in the query. In the Ext/Column field, type the name of the column where the LOB type extension is stored.

If you specify None, the LOB data will be sent to your browser in binary format and DB2 Web Query will rely on the browser to determine the type of data.

11.      If you have SQL\PA installed on you system and your query has not been analyzed by SQL/PA, "Not Analyzed" will appear next to SQL/PA in the SQL/PA section. To analyze your query with SQL/PA, click Analyze in the SQL/PA section of the Settings section. SQL/PA analyzes one statement at a time. Therefore, if you have more than one SQL statement embedded in your query, you will see results in a cumulative format. To set your SQL/PA analysis options, click Analyze options.

Note:     If you do not have SQL/PA installed, "Not Installed" will appear next to SQL/PA in the SQL/PA section.

12.      Optional: To edit the query click Edit SQL.

13.      To run the query click Next.

Note:     You can also save the query by clicking Save.