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 > how to run a sql file by calling from another sql file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-11, 01:40
super_mpk super_mpk is offline
Registered User
 
Join Date: May 2011
Posts: 15
how to run a sql file by calling from another sql file

Hi all,

I am writing one sql script where i am writing some db2 commands like connect ,select etc.

but I have to store output of select command inside another file and I want to execute the file from my script .

so please anyone tell me how to call another .sql file from a script on db2 command line.

I am using the command db2 -vtf filename to execute the file from db2 command window. but it is giving error when i trying to write the same cmd in file.
Reply With Quote
  #2 (permalink)  
Old 05-26-11, 07:30
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
You cannot do what you want. The closest thing to that would be to invoke a new instance of CLP from within your script:
Code:
!db2 -vtf newscript.sql
Be aware that it will create a new execution environment, meaning, in particular, that you will have to create a new connection.
Reply With Quote
  #3 (permalink)  
Old 05-27-11, 11:49
MarkhamDBA MarkhamDBA is offline
Registered User
 
Join Date: Dec 2008
Location: Toronto, Canada
Posts: 381
you can not. you have 2 options:

1. put it in a script so you can call it from another script
just add 'db2 -<option> to your sql command.

2. put it in an sql file and call it from a script
for example: db2 -tvf file.sql
__________________
DB2 v9.5 ESE on AIX v6.1/ v9./10 on z/OS
Reply With Quote
  #4 (permalink)  
Old 05-30-11, 03:16
super_mpk super_mpk is offline
Registered User
 
Join Date: May 2011
Posts: 15
running sql script

Thanks all,

I did it by creating a batch file and I put db2 commands inside it.

and run it from db2 command window.

thanks for your guidence....
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