If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > can I pass a system variable into a sql file executed by db2?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-02-03, 23:26
r390gt1 r390gt1 is offline
Registered User
 
Join Date: May 2003
Posts: 27
can I pass a system variable into a sql file executed by db2?

eg.
I have a sql file called step1.sql and its connent as follows:

step1.sql
-------------------------------------------------------------------
connect to mydb;

select * from myschema.mytable
where myname = 'xyz';

connect reset;
--------------------------------------------------------------------

i run this file thru the command:
db2 -tvf step1.sql


I wonder if I can use the system variable for the database name and the value of myname......as follows.. ( of course, the following stuff in not working), what I want is to pass a value from the system in to the db2 command line processor.........

ie. in unix platform for example

in unix console,
-------------------------------------------------------------------
export dbname=mydb
export myvalue=xyz

step1.sql
-------------------------------------------------------------------
connect to $dbname;

select * from myschema.mytable
where myname = $myvalue;

connect reset;
--------------------------------------------------------------------

is there any way to do thing like the above??
use stored procedural ??
Reply With Quote
  #2 (permalink)  
Old 12-03-03, 02:24
jammann jammann is offline
Registered User
 
Join Date: Jul 2003
Location: Switzerland, Basle
Posts: 10
on unix you can use a shell-script with embedded SQL-input

example
-------------------------------------------
#!/bin/ksh
# or whatever shell you like

dbname=mydb
myvalue="'xyz'"
# note the double-quote followd by single-quote surrounding the value

db2 +p -tf- <<.EOFSQL
-- START of SQL
connect to $dbname;

select * from myschema.mytable
where myname = $myvalue;

connect reset;
.EOFSQL
# here continues the shell-script
# instead of .EOFSQL you can use any other string to begin/terminate
# the inline input (NO leading spaces! for the terminating line)
Reply With Quote
  #3 (permalink)  
Old 12-04-03, 23:23
r390gt1 r390gt1 is offline
Registered User
 
Join Date: May 2003
Posts: 27
thanks....

thanks.... jammann
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On