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 > Batch file for Multiple SQL, multiple output files

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-14-06, 08:41
cheech cheech is offline
Registered User
 
Join Date: Feb 2006
Posts: 2
Question Batch file for Multiple SQL, multiple output files

Hello all!

I am trying to create a batch file for DB2 that will take multiple queries within the batch file and output them to several files instead of appending them all into one large file. Here is what I have so far:

from the command line prompt in the command window I can enter the command db2 -r C:\Docume~1\MyDocu~1\Query\mondayresults.txt -f C:\Docume~1\MyDocu~1\Query\mondaybatch.txt and this will run all 10 of the queries in the mondaybatch.txt file, and will create the mondayresults.txt file and all the results will be located in order within that file, but what I want to do is to output each of the 10 queries into seperate files like C:\Docume~1\MyDocu~1\Query\monday1.txt etc... If anyone can help me with the syntax inside the file to output to different files i would appreciate it!

Adam
Reply With Quote
  #2 (permalink)  
Old 02-22-06, 23:42
chemaster chemaster is offline
Registered User
 
Join Date: Feb 2006
Posts: 13
I have ran simular scripts with the following. You can created the ddl's on the fly as I did below and run each one separatly or make the ddl up beforehand. Either way you can save the results under a different name and you can also pass in arguments to include into your scripts. I am fairly new to db2 and this may not be effective but I have been doing simular things for several months. I have stored about 100 different scripts on my ipod nano that are menu driven. This way I can quickly connect to over 50 different PC with DB2 access and query away and save the reports to my ipod within seconds.

@echo off
cls

if exist .\ddl\script1.ddl del .\ddl\script1.ddl
if exist .\reports\report1.txt del .\reports\report1.txt

if exist .\ddl\script2.ddl del .\ddl\script2.ddl
if exist .\reports\report2.txt del .\reports\report2.txt

if exist .\ddl\script3.ddl del .\ddl\script3.ddl
if exist .\reports\report3.txt del .\reports\report3.txt


::script1
echo connect to DB_NAME user USER_NAME using 'PASSWORD' >> .\ddl\script1.ddl
echo select * from TABLE_1 >> .\ddl\script1.ddl
echo terminate >> .\ddl\script1.ddl

db2cmd /c db2 -f .\ddl\script1.ddl -z .\reports\report1.txt

::script2
echo connect to DB_NAME user USER_NAME using 'PASSWORD' >> .\ddl\script2.ddl
echo select * from TABLE_2 >> .\ddl\script2.ddl
echo terminate >> .\ddl\script2.ddl

db2cmd /c db2 -f .\ddl\script2.ddl -z .\reports\report2.txt

::script3
echo connect to DB_NAME user USER_NAME using 'PASSWORD' >> .\ddl\script3.ddl
echo select * from TABLE_3 >> .\ddl\script3.ddl
echo terminate >> .\ddl\script3.ddl

db2cmd /c db2 -f .\ddl\script3.ddl -z .\reports\report3.txt

--- Small Sample Passing Arguments ---

echo select orderno, status, %1 from orderheader where %1 like '%%%2%%' >> .\ddl\%0.ddl

TO RUN SCRIPT
find.bat last_name Johnson

Returns orders with Johnson as the last name OR

find.bat product_desc nut

Return all orders with nut as part of order

Like I said, I am new to this and there may be better ways.

Last edited by chemaster; 02-23-06 at 00:24.
Reply With Quote
  #3 (permalink)  
Old 02-28-06, 11:52
cheech cheech is offline
Registered User
 
Join Date: Feb 2006
Posts: 2
you'll have to excuse me, I am not very familiar with the scripting. That is probably why it is so hard for me to do. i really don't know what you wrote is trying to do or where it saves the info. I need the results of the queries as a text file on my c:\ drive in this path C:\Docume~1\AWM1732\MyDocu~1\Query\. Is there a way to accomplish this, or maybe can you explin what the script you have is doing, so i can understand it better?
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