Click here to Skip to main content
15,904,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I execute the script file using batch file in sql server

If you mean executing a script from command line, one excellent tool is sqlcmd[^] utility.

You can pass the script as a parameter along with all credentials etc.
Share this answer
1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance.
2. Expand SQL Server Agent, create a new job or right-click an existing job, and then click Properties.For more information about creating a job.
3. In the Job Properties dialog, click the Steps page, and then click New.
4. In the New Job Step dialog, type a job Step name.
5. In the Type list, choose Operating system (CmdExec).
6. In Run as list, select the proxy account with the credentials that the job will use. By default, CmdExec job steps run under the context of the SQL Server Agent service account.
7. In the Process exit code of a successful command box, enter a value from 0 to 999999.
8. In the Command box, enter the operating system command or executable program.
9. Click the Advanced page to set job step options, such as: what action to take if the job step succeeds or fails, how many times SQL Server Agent should try to execute the job step, and the file where SQL Server Agent can write the job step output. Only members of the sysadmin fixed server role can write job step output to an operating system file.
Share this answer
1) Open Notepad
2) Write below command. Ecxclude Var if you don't want to pass parameter. Replace procedure name with you procedure name
SET var=Parameters
BCP "EXEC ProcedureName '%var%' " -t`~ -c -T

3) Save this file as batch file ".bat "

That's it
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900