I am creating a job which takes backup of a database and with the filename suffixing today's date. But I'm getting below error.
DECLARE @Query NVARCHAR(MAX)
SET @Query = 'BACKUP DATABASE [DBName] TO DISK = ''D:\Backups\DBName_'+cast(convert(date,getdate())as varchar)+'.bak'
EXEC sp_executeSql @Query
Error Message:
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string 'D:\Backups\DBName_2017-07-07.bak'.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'D:\Backups\DBName_2017-07-07.bak'.