I\'m using the below to backup a db from a SQL job. Can someone tell me how to add the current date to the output filename? Preferably in YYYYMMDD format.
BACK
Use the following
DECLARE @BackupFileName varchar(20)
SELECT @BackupFileName = '\\ServerName\SharedFolder\DatabaseName_' + CONVERT (VarChar, GetDate(), 112) + '.bak'
BACKUP DATABASE [myDB] TO DISK = @BackupFileName WITH NOFORMAT, INIT, NAME = N'myDB', SKIP, REWIND, NOUNLOAD, STATS = 10
Read up on Cast and Convert here http://msdn.microsoft.com/en-us/library/ms187928.aspx