Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / February 2007

Tip: Looking for answers? Try searching our database.

db2 sql clp

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pspivack@snet.net - 03 Feb 2007 21:44 GMT
I have a UNIX .sh script that invokes a DB2 SQL .sql script that
contains the following:

db2 -t -f parmtest.sql -z parm_output.log

My question is how can I pass a parameter to the parmtest.sql script
from the db2 clp (if it is possible) and how does one reference the
parameter in the .sql script. The .sql script is not a procedure.
Phil Sherman - 04 Feb 2007 02:43 GMT
The simple answer is: "you can't".

The command line processor, when reading a file containing SQL
statements has no ability to pass parameters and perform on-the-fly
modification to the statements.

All is not lost, however. You can take the entire .sql script and embed
it into the .sh script. Preface each statement in the .sql script with
an "echo" command and append (>>) all output of the "echo" commands
except the first to the .sql script. The first "echo" statement should
redirect (>) its output to the .sql file. Now you can use parameters to
the .sh script to modify the SQL statement(s).

Remember that the userid running the .sh script must have write access
to the .sql file for this to work.

I'd also change the options on the db2 command to -tvf. This will list
the SQL statements in the output. Of course, if you pass the output into
additional automated processing, you'll need to handle the additional
data records in the output file.

Phil Sherman

> I have a UNIX .sh script that invokes a DB2 SQL .sql script that
> contains the following:
[quoted text clipped - 4 lines]
> from the db2 clp (if it is possible) and how does one reference the
> parameter in the .sql script. The .sql script is not a procedure.
Lennart - 04 Feb 2007 06:31 GMT
On Feb 3, 10:44 pm, pspiv...@snet.net wrote:
> I have a UNIX .sh script that invokes a DB2 SQL .sql script that
> contains the following:
[quoted text clipped - 4 lines]
> from the db2 clp (if it is possible) and how does one reference the
> parameter in the .sql script. The .sql script is not a procedure.

You can't, but there are ways around. Assume parmtest.sql looks like:

select * from T where T.a = ? and T.b = ?

You can change it to (for example)

select * from T where T.a = @@P1@@ and T.b = @@P2@@

Now you can do this as:

sed -e "s/@@P1@@/<your p1>/g" -e "s/@@P2@@/<your p2>/g" < parmtest.sql
> tmp.sql
db2 -t -f tmp.sql -z parm_output.log

/Lennart
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.