Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665

    Unanswered: db2 -vtf Variables

    Is it posable to pass a variable when using the DB2 -vtf Filename.txt syntax?
    ------------
    And back to SQL Server....I always find my way home
    View my Linkedin profile

  2. #2
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    A variable that is used and resolved inside the SQL script? No. But you can write a simple shell script that invokes the DB2 command line. In the commands in that shell script, you can use variables. Here is an example:
    Code:
    #!/bin/sh
    
    TABLE=syscat.tables
    
    db2 "CONNECT TO <dbname>"
    db2 "SELECT count(*) FROM ${TABLE}"
    db2 "CONNECT RESET"
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  3. #3
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    The problem we are having with the shell script is that we have not found a way to format long sql so that it can be read by humans. Is there a work around for that?
    ------------
    And back to SQL Server....I always find my way home
    View my Linkedin profile

  4. #4
    Join Date
    Jan 2007
    Location
    Jena, Germany
    Posts
    2,721
    I would do this in exactly the same way as any other SQL script, except that you have quotes wrapped around and a continuation character at the end of each line (except the last):
    Code:
    db2 "SELECT ..." \
        "FROM ..."
    Or you use something like this:
    Code:
    db2 <<EOT
    CONNECT TO ...
    
    SELECT ...
    FROM   ...;
    
    CONNECT RESET;
    EOT
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

  5. #5
    Join Date
    Aug 2002
    Location
    Charlotte NC
    Posts
    665
    What does the db2 <<EOT mean?
    ------------
    And back to SQL Server....I always find my way home
    View my Linkedin profile

  6. #6
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Quote Originally Posted by JDionne
    What does the db2 <<EOT mean?
    http://en.wikipedia.org/wiki/Here_document
    ---
    "It does not work" is not a valid problem statement.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •