• WayneS (6/13/2009)


    Okay, here's some code to demonstrate what I'm talking about.

    Save this code as a batch file, and run it:

    for %%a in ("%windir%\*.exe") do SQLCMD -S ServerName -d master -E -Q"set nocount on;select '%%a'" -o "%temp%\output.txt"

    type %temp%\output.txt

    pause

    cls

    echo %date% %time% > "%temp%\output.txt

    for %%a in ("%windir%\*.exe") do SQLCMD -S ServerName -d master -E -Q"set nocount on;select '%%a'" >> "%temp%\output.txt"

    type %temp%\output.txt

    pause

    del %temp%\output.txt

    At the first pause, the contents of the output file are displayed. All that is in it is the last *.exe.

    At the second pause, the contents of the output file are again displayed. The prior contents are erased, and all exe files are listed.

    This demonstrates the point the OP was making.

    You've added a line of code the OP didn't have in the original problem and that new line is the one responsible for the incorrect operation.

    echo %date% %time% > "%temp%\output.txt

    You've neglected to use ">>" in that line of code and that's what resets file. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)