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 > db2 -vtf Variables

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-07, 03:36
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
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
Reply With Quote
  #2 (permalink)  
Old 10-17-07, 04:24
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #3 (permalink)  
Old 10-17-07, 05:05
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
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
Reply With Quote
  #4 (permalink)  
Old 10-17-07, 06:58
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
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
Reply With Quote
  #5 (permalink)  
Old 10-17-07, 09:01
JDionne JDionne is offline
Registered User
 
Join Date: Aug 2002
Location: Charlotte NC
Posts: 663
What does the db2 <<EOT mean?
__________________
------------
And back to SQL Server....I always find my way home
View my Linkedin profile
Reply With Quote
  #6 (permalink)  
Old 10-17-07, 09:37
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by JDionne
What does the db2 <<EOT mean?
http://en.wikipedia.org/wiki/Here_document
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