How to pass a shell variable to a .sql file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Suryaaravindh
    New Member
    • Sep 2010
    • 1

    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
  • zenworkks

    #2
    Passing a shell variable to a .sql file
    you can use:

    Code:
    #!/usr/bin/ksh
    
    table="syscat.tables"
    db="bet"
    
    db2 -t -x -z sql.out +p <<-eof
    connect to ${db};
    select * from ${table};
    terminate;
    eof

    Comment

    Working...