If I run the backup in a job this works:

sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d LL_DB -Q "
EXECUTE [dbo].[DatabaseBackup] @Databases = 'AVAILABILITY_GROUP_DATABASES', 
@Directory = N'\\backup\SQL\', 
@BackupType = 'FULL', @ChangeBackupType = 'Y', @Verify = 'Y', @CleanupTime = 48, @CheckSum = 'Y', @LogToTable = 'Y'" -b

If I stripe the backup like so:

sqlcmd -E -S $(ESCAPE_SQUOTE(SRVR)) -d LL_DB -Q "EXECUTE [dbo].[DatabaseBackup] @Databases = 'AVAILABILITY_GROUP_DATABASES', 
@Directory = N'\\backup\SQL\Drive1\, \\backup\SQL\Drive2\, \\backup\SQL\Drive3\, 
\\backup\SQL\Drive4\, \\backup\SQL\Drive5\, \\backup\SQL\Drive6\,
\\backup\SQL\Drive7\, \\backup\SQL\Drive8\, \\backup\SQL\Drive9\, \\backup\SQL\Drive10\', 
@BackupType = 'FULL', @Verify = 'Y', @CleanupTime = 24, @CheckSum = 'Y',
@LogToTable = 'Y'" -b

I get the following error:

Msg 105, Level 15, State 1, Server SQLSERVER, Line 1 Unclosed quotation mark after the character string 'EXECUTE [dbo].[DatabaseBackup] @Databases = 'AVAILABILITY_GROUP_DATABASES', '.

I can execute the same code as T-SQL and it works, also if I put the T-SQL in a job it works (although it gives me error 50000, but still completes!), I've been over it a few times and can't see what I might be missing, do I need to put extra quotation marks in the SQLCMD job?

  • Your code seems to work on my test machine. Have you anonymized anything?
    – Tom V
    Feb 8, 2018 at 9:44
  • Only the server name and the server name in the path but that is just normal characters, everything is as it is in the job, it's quite annoying because the SQL part works, it's just when I put it in the sqlcmd.
    – Mark
    Feb 8, 2018 at 10:59
  • You might be running into DOS and SQLCMD line continuation problems. Can you put the T-SQL in a text file and use the SQLCMD -i (input parameter) to point to the text file? Feb 8, 2018 at 12:04

1 Answer 1


Everything needs to be on one line...not multiple so we humans can read it....same as if you were typing it into SQLCMD. The second you hit return it starts executing from there.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.