running db2 sql and exporting output from ksh scipt

Hi there,

I am trying to write a shell script as root on AIX 5.3 where I change user to db2inst1, connect to our db2 database, run a sql select query and export the result of the query to a file.

The code I have so far is as follows:-

#!/usr/bin/ksh

su - db2inst1 -c "db2 connect to <db_name>; set schema APP;"
export to /home/db2inst1/esb_checks/kicker/kicker.del of del;
select * from <TABLE_NAME>;

The script connects OK, and sets the correct schema however an error is produced as follows when running and exporting the sql code:-

/home/db2inst1/esb_checks/kicker/kicker.del: This is not a
n identifier.

When I login as the db2inst1 user and run the query manually it works fine:-

connect to <database_name>;
set schema APP;
export to /home/db2inst1/esb_checks/kicker/kicker.del of del;
select * from <TABLE_NAME>;

I've scoured the UNIX forums and found nothing to resolve my problem, I have found a few threads that have pointed me in what I have thought is the right direction, but I am still at a loss.

I'm wondering if this is a permissions issue? or maybe not?

Any help or expert pointers, much appreciated

Cheers

Candlino