Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2006
    Posts
    2

    Question Unanswered: 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

  2. #2
    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 01:24.

  3. #3
    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?

Posting Permissions

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