Search code examples
sql-serverbatch-filecmdsql-server-job

Running batch file which runs 2 other batch files from SQL Server job


I have this step in sql server job enter image description here

AAA.bat content is this

call BBB.bat
call CCC.bat

BBB.bat and CCC.bat each run ETL packages. When I run above step it throws error

BBB.bat is not recognized as an internal or external command, operable program or batch file... CCC.bat is not recognized as an internal or external command, operable program or batch file

However, when I replace AAA.bat with either BBB.bat or CCC.bat it works as intended.


Solution

  • Are BBB.bat and CCC.bat in the same directory as AAA.bat? You need to set the working directory first. In AAA.bat add the following at the top of the file:

    cd /d D:\Path\Client1
    

    Or, call BBB.bat and CCC.bat using their full path.

    A possibly better solution, depending on your environment and needs, would be to have your job contain two steps, each one calling the appropriate batch file (BBB or CCC) separately. That way, if you have a failure, its very obvious which batch file had a problem.