Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute a stored procedure in a SQL Agent job?

I am using SQL Server 2008 and I need to run a SQL Job from SQL Server Agent. I am new to SQL Server Job and I want to execute a stored procedure regularly from a SQL Server Job. But I did not find where to specify the executed stored procedure other than copy & paste SQL commands.

Here is my screen snapshot:

enter image description here

Any ideas how to assign stored procedure to execute in SQL Server Job?

like image 811
George2 Avatar asked Aug 01 '09 09:08

George2


People also ask

How do you call a stored procedure in a scheduled job in SQL Server?

Expand SQL Server Agent, expand Jobs, right-click the job that you want to schedule, and click Properties. Select the Schedules page, and then click Pick. Select the schedule that you want to attach, and then click OK.

How do I trigger a SQL Agent job?

SQL Server Agent is the job scheduling tool for SQL Server. To execute a job on demand using the GUI, open the SQL Server Agent tree, expand Jobs, select the job you want to run, right click on that job and click 'Start Job' and the job will execute.

How do you automate a stored procedure in SQL Server?

Now, to automate the execution of a stored procedure, we need to schedule its execution. So, when the specified time has reached the stored procedure will automatically get executed. Now, in SQL Server, we usually use the SQL Server Agent to schedule a job that consists of executing a stored procedure.


2 Answers

You just need to add this line to the window there:

exec (your stored proc name) (and possibly add parameters) 

What is your stored proc called, and what parameters does it expect?

like image 154
marc_s Avatar answered Sep 19 '22 17:09

marc_s


As Marc says, you run it exactly like you would from the command line. See Creating SQL Server Agent Jobs on MSDN.

like image 20
Dan Diplo Avatar answered Sep 18 '22 17:09

Dan Diplo