SQLCMD and OSQL - behaviour difference

  • The command

    osql -S %COMPUTERNAME% -E -w 512 -Q "SET NOCOUNT ON SELECT 'EXECUTE master.dbo.xp_sqlmaint N''-D ' + name + ' -VrfyBackup -BkUpMedia DISK -BkUpDB "D:\MSSQL\Backup" -DelBkUps 10DAYS -BkExt "BAK"''' FROM dbo.sysdatabases WHERE name NOT IN ('tempdb')" -o test.sql

    works fine in a batch file, but fails when osql is replaced with SQLCMD (it complains about the -D switch for the use of sqlmaint which is enbedded in the query string).

    Does anyone know why this should be? And what changes could be made to enable the command to run against SQLCMD?

    Many thanks!

     

  • it may be that sqlcmd thinks the -D flag is meant for it, when in fact it is internal to the query passed on the cmd line.  This would be a bug in sqlcmd's cmd line parsing code.

    Also it seems to me your quotes might be confusing it, because you have double quotes inside your query.  Try replacing "D:\MSSQL\Backup" with D:\MSSQL\Backup, and "BAK" with BAK.

    Another thing to try would be to put the query in a file (query.sql) and then pass it to sqlcmd with the -i flag.

    ---------------------------------------
    elsasoft.org

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

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