help with SQLCMD

  • Based on the microsoft link above, I found this very effective workaround

    After each insert or update statement I have this line of code.

    PRINT '(' + RTRIM(@@ROWCOUNT) + ' row(s) affected.)';

    Note that 2008 R2 SQLCMD does not bracket the "s" in parentheses as was done in 2005.

    For 2008 output (when it works)

    343 rows affected

    1 rows affected

  • Maybe I'm oversimplifying but your problem may be in this step:

    master.dbo.xp_cmdshell 'sqlcmd -Sserver -d database -W -i "C:\SQL\SQLQuery2.sql" -o "C:\SQL\Output\SQLQuery2.sql"'

    Your output file is the same name and path as your input file. You are overwriting the file. Your delete statement runs, writes "(0) Rows affected" thereby overwriting your insert statements in the same file. Make your output file something different like "C:\SQL\SQLQuery2Output.sql".

    Please correct me if I'm wrong.

Viewing 2 posts - 16 through 16 (of 16 total)

You must be logged in to reply to this topic. Login to reply