Consider the following command, which I've wrapped for readability:
sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d master -Q "EXECUTE [dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = N'C:\Backup', @BackupType = 'DIFF', @Verify = 'Y', @CleanupTime = NULL, @CheckSum = 'Y', @LogToTable = 'Y'" -b
It returns the following error:
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near 'E'. Msg 103, Level 15, State 4, Line 3 The identifier that starts with 'EXECUTE [dbo].[DatabaseBackup] @Databases = 'USER_DATABASES', @Directory = N'C:\Backup', @BackupType = 'DIFF', @Verify = 'Y', @C' is too long. Maximum length is 128.
When I remove the sqlcmd
it works. I know I'm doing something wrong, however I don't understand what the problem is.
Best Answer
I just put your command into a SQL Server Agent Jobstep configured to use CmdExec; it ran the command perfectly.
The result was a job failure for me because I don't have the
dbo.DatabaseBackup
stored procedure:However, this indicates that sqlcmd was successfully executed.