Unanswered: Batch file for Multiple SQL, multiple output files
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!
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.
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
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
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?