Search code examples
sql-serverdatabase-administrationsqlcmdinvoke-sqlcmd

multiple sqlcmd commands in a batch file


I have multiple sqlcmd commands to run at a time from a batch file. Each statement when executed separately works perfectly. But if I give like a 5 sqlsmd commands in a bat file it only executes the first one and then I see 1> in my command line screen and nothing happens. How to resolve this?

Note: CALL statement before each line didn't work That is the only solution i found in my reseach

example of what i'm doing::

sqlcmd -S servername-q "EXEC msdb.dbo.prc_Backup @BackupType = 'L'       ,@DBName = 'db' ,@BackupDir = 'J:\MSSQL10.MSSQLSERVER\MSSQL\Backup\db2dba' ,@RetainHours = 47       , @create_sub_dir = 0      " >> C:\tlogresult.txt
sqlcmd -S servername -q "EXEC msdb.dbo.prc_Backup @BackupType = 'L'      ,@DBName = 'DB2RuntimeMigration' ,@BackupDir = 'J:\MSSQL10.MSSQLSERVER\MSSQL\Backup\DB2RuntimeMigration' ,@RetainHours = 47         , @create_sub_dir = 0      " >> C:\tlogresult.txt

Solution

  • I'm not able to run it via bat file. What i am able to do is to run the commands with QUIT at the end of each command from the command line.