473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Need sample DB2 script called by AIX script

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 ?

I am guessing that AIX script would looks like this:
"db2" < "C:\db2SQL.SCRIPT"
echo status: (RC=%errorlevel% )
Nov 12 '05 #1
4 9683
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 ?

I am guessing that AIX script would looks like this:
"db2" < "C:\db2SQL.SCRIPT"
echo status: (RC=%errorlevel% )


That looks very much Windows-like.

How about the following...

SQL script named "query.sql":
-------------------
SELECT *
FROM syscat.tables;
-------------------

AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh

db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------
Or you do something like this:
-------------------
db2_out=`db2 -t -v -f query.sql`
echo $db2_out
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #2
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 ?

I am guessing that AIX script would looks like this:
"db2" < "C:\db2SQL.SCRIPT"
echo status: (RC=%errorlevel% )


That looks very much Windows-like.

How about the following...

SQL script named "query.sql":
-------------------
SELECT *
FROM syscat.tables;
-------------------

AIX shell script (assuming ksh or bash or so):
-------------------
#!/bin/sh

db2 -t -f query.sql
if [ $? ]; then
echo "Script failed"
fi
-------------------
Or you do something like this:
-------------------
db2_out=`db2 -t -v -f query.sql`
echo $db2_out
--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #3
"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
Nov 12 '05 #4
"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
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brian Murphy | last post by:
<?php /* I need your help. I'd be very thankfull if write me this script.I need a script that displays a list of categories and subcategories like this: <select name="category"> <option...
5
by: deko | last post by:
In regard to running php scripts with cron - Here is a sample script: <?php //debug.php echo "<br> This is a test"; ?> I can call debug.php from a web page on my site like this:
1
by: Dan | last post by:
Hi, I am using the Employee.fdb sample that comes with Firebird 1.5.1. Everything resides on a WinXP Pro pc. I set up an ODBC connection called "FB Employee Sample" and tested it with MS Access...
3
by: John MacIntyre | last post by:
Hi, Can anybody give me a hint as to how to convert a javascript array into a vbscript array? BTW-it only needs to work in IE5 & 6 Thanks in advance, John MacIntyre VC++ / VB / ASP /...
4
by: Bob | last post by:
Below is sample code that illustrates what I'm trying to do. For sake of brevity I didn't include the properties of buildBtn that determine what data to request. The problem is I never see...
0
by: David | last post by:
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...
17
by: freemann | last post by:
Can anyone provide example code showing how to send form results to a results page, email and a comma delimited file? Notice that I need it going to all three locations. Details: I have forms...
7
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
4
by: Jonathan Wood | last post by:
I'm trying to duplicate an HTML sample I have using my ASP.NET pages. The sample contains the following within the <headtag: <script type="text/javascript" src="flashobject.js"></script>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.