I have created a batch with the following. ( Batch file name is BACKUP_TASK.bat )
SQLCMD -E -S SQLEXPRESS
DECLARE @DatabaseName sysname = N'DEMO_DB',
@DatabaseBackupFileName varchar(255);
SET @DatabaseBackupFileName = 'C:\sql\' + @DatabaseName + '_' + REPLACE(replace(convert(varchar(40),getdate()),' ','_'),':','_') + '.bak';
BACKUP DATABASE @DatabaseName TO DISK = @DatabaseBackupFileName;
GO
exit
exit
If I copy paste this code directly to Command Prompt it Executes as Expected.But if I double click on the batch file then the Command Prompt opens up and only the first line is compiled and nothing happen further more. So what I am doing here wrong ? Please help me solve this.