"Knut Stolze" <st****@de.ibm.com> wrote in message
news:c6**********@fsuj29.rz.uni-jena.de...
David wrote: Hi,
I am new to DB2. Does someone have a sample DB2 script they can post
here? All I want to do is execute a SQL query like this:
SELECT * FROM TABLE
Also, can someone post a sample AIX script that calls executes this
DB2 script ?
[snip] How about the following...
[snip] AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh
db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------
Another option is to inline your SQL like so
#-------------------
#!/bin/sh
echo "
SELECT * FROM sometable
;" | db2 +p -vt
#-------------------
which has the benefit of allowing expansion of shell variables, e.g.:
#-------------------
#!/bin/sh
months="01 02 03 04 05 06 07 08 09 10 11 12"
for t in $months; do echo "
CREATE TABLE FACT_2004_$t
( I INT NOT NULL
, C CHAR(5)
)
;
" | db2 +p -vt ;done
#-------------------
Regards
Paul Vernon
Business Intelligence, IBM Global Services