Invoking the batch file using jobs

  • hi.

    I want to invoke a batch file using jobs. the batch file say a.bat which inturn calls another batch file b.bat to initiate the compilation of 4000 SPs through sqlcmd. can anyone help me ?

  • The idea is pretty simple, follow the below steps:

    1. Create a.bat and add the below content:

    sqlcmd -i"C:\b.bat" -E -cEXIT -o "C:\Error.txt"

    2. Create b.bat that includes the T-SQL statements:

    "CREATE LOGIN [FAREAST\rayadav] FROM WINDOWS WITH DEFAULT_DATABASE=[master]"

    GO

    "CREATE LOGIN [FAREAST\ashwim] FROM WINDOWS WITH DEFAULT_DATABASE=[master]"

    3. Create the job and choose the step subsystem as "Opertaing System Command(CmdExec)" for e.g.

    EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'cmd',

    @step_id=1,

    @cmdexec_success_code=0,

    @on_success_action=1,

    @on_success_step_id=0,

    @on_fail_action=2,

    @on_fail_step_id=0,

    @retry_attempts=0,

    @retry_interval=0,

    @os_run_priority=0, @subsystem=N'CmdExec',

    @command=N'C:\a.bat',

    @flags=0

    r, manish

  • Thanks Manish ,

    I tried this and its working fine

    USE master;

    EXEC xp_cmdshell '"full path\job.bat"'

    GO

  • Thanks Manish ,

    I tried this and its working fine

    USE master;

    EXEC xp_cmdshell '"full path\job.bat"'

    GO

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply