Previous Topic: Examples: Running SQL Statements Against Microsoft SQL Server Database TablesNext Topic: File Trigger Jobs


Examples: Running SQL Statements Against IBM DB2 Database Tables

This topic contains examples of SQL jobs that run SQL statements against IBM DB2 database tables.

Example: Add a Row to an IBM DB2 Database Table

Suppose that you want a job to add a row of data to the STAFF table under the user entadm.

AGENT DB_AGENT
USER entadm
DB_URL jdbc:db2://10.1.4.131:50000/SAMPLE
SQL 'INSERT into ENTADM.STAFF(ID, NAME, DEPT, JOB, YEARS, +
  SALARY, COMM) VALUES(556, ''Jonson'', 84, ''Sales'', 1, +
  40500.50, 100)'

Example: Update a Row in an IBM DB2 Database Table

Suppose that you want a job to update a record in the STAFF table under the user entadm. The job changes the years to 3 for the employee with the name Jonson.

AGENT DB_AGENT
USER entadm
DB_URL jdbc:db2://10.1.4.131:50000/SAMPLE
SQL 'UPDATE ENTADM.STAFF SET YEARS=3 where NAME=''Jonson'''

Example: Delete a Row from an IBM DB2 Database Table

Suppose that you want a job to delete a row from the STAFF table under the user entadm for the employee with the name Jonson.

AGENT DB_AGENT
USER entadm
DB_URL jdbc:db2://10.1.4.131:50000/SAMPLE
SQL 'DELETE FROM ENTADM.STAFF where NAME=''Jonson'''

Example: Return Data from an IBM DB2 Database Table that Matches a Condition

Suppose that you want a job to query the STAFF table under the user entadm for employees that have salaries greater than 40,000. If the query returns an employee name that begins with the letter J, the job completes.

AGENT DB_AGENT
USER entadm
DB_URL jdbc:db2://10.1.4.131:50000/SAMPLE
SQL 'SELECT NAME FROM ENTADM.STAFF where SALARY > 40000'
JOB_CRITERIA NAME=J.*
OUTPUT_FILE /staff/salary.txt

For example, the salary.txt file contains the following output:

Output for: SELECT NAME FROM ENTADM.STAFF where SALARY > 40000

NAME
-----------
Jonson