473,320 Members | 2,012 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,320 software developers and data experts.

How to pass a shell variable to a .sql file

I am calling a .sql file from my shell script. I want to pass a shell variable to the .sql file and use it in my query.

employee1.ksh
#!/usr/bin/ksh
db2 connect to testdb user testuser
$deptid = 10
db2 -vsf /home/testdir/query.sql
db2 terminate

query.sql
select * from employee where deptid = (I want to use $deptid here)

Is it possible to do something like that? Please help
Sep 22 '10 #1
1 7825
Passing a shell variable to a .sql file
you can use:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/ksh
  2.  
  3. table="syscat.tables"
  4. db="bet"
  5.  
  6. db2 -t -x -z sql.out +p <<-eof
  7. connect to ${db};
  8. select * from ${table};
  9. terminate;
  10. eof
  11.  
Oct 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: CES | last post by:
All, I was wondering is their a way of passing a variable into an eval() statement? I've created a custom eval() dll to use with my VB.net code. Every thing works fine until I try to pass a...
3
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on...
1
by: I.am.the.Buddha | last post by:
I am still learning asp and sql. I am having trouble with passing a variable to within an sql statement. I am sure it is something simple like misuse of quotes. Since it may help if i say what i...
2
by: David Dawson | last post by:
I have forgotten a lot about SQL and would like to be (gently) reminded how to do this: In a MySQL query on the database (one table with 15 variable length fields, I want to put each field into a...
7
by: Brian Tkatch | last post by:
This is a shell question (bash), but i'm more familiar with this group, so i hope noone minds. I have a bash shell script which needs to query the database and return information into a...
1
by: shahparags | last post by:
Hello, I am developing a script where one of my Bacth command uses a XML file as an argument. This XML file contains the Path of the Data to be Converted from one format to another. Now My...
2
by: Geoff Cox | last post by:
Hello, The code below is aimed at passing the date in the yyyyMMdd format from the javascript calendar in an html file to the php in a another file which then searches a MySQL database. For...
5
by: goldtech | last post by:
Hi, I'm passing what I think is a string parameter to another Python program (spawn.py) - see the code snip below. But only the counter part gets printed to a log file via spawn.py. Yet the...
1
by: looza | last post by:
Hi All, I have a bunch of shell script files that use a common shell script file that contains certain global variables that are declared and initialized or derived by some arithmatic. I have...
7
by: chazzy69 | last post by:
Ok basically i need to figure out why i cant pass a variable as a parmater in the fwrite function. heres the code that does NOT work - $output = "hello world"; //note not the actual string...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.