• carissa.chris (6/12/2009)


    I have a batch file that runs all the sql scripts in a specified folder. The output is written to output.txt. However, each time a sql script is executed, the output.txt file is overwritten. Is there a way to append to the output.txt file?

    Here is my batch file:

    for %%a in ("E:\Source\APP_30\SQL\Structure\*.sql") do SQLCMD -S ServerName -d DatabaseName -E -i %%a -o "E:\output.txt"

    for %%a in ("E:\Source\APP_30\SQL\SP\*.sql") do SQLCMD -S ServerName -d DatabaseName -E -i %%a -o "E:\output.txt"

    for %%a in ("E:\Source\APP_30\SQL\Triggers\*.sql") do SQLCMD -S ServerName -d DatabaseName -E -i %%a -o "E:\output.txt"

    Well, BOL clearly states that the output file will be overwritten.

    I suggest you make the output filename dynamic:

    for %%a in ("E:\Source\APP_30\SQL\Structure\*.sql") do SQLCMD -S ServerName -d DatabaseName -E -i %%a -o "E:\%%aoutput.txt"

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2