How do I execute a stored procedure in a SQL Agent job?
127,794
Solution 1
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?
Solution 2
As Marc says, you run it exactly like you would from the command line. See Creating SQL Server Agent Jobs on MSDN.
Related videos on Youtube
Author by
George2
Updated on October 05, 2020Comments
-
George2 over 3 years
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:
Any ideas how to assign stored procedure to execute in SQL Server Job?
-
George2 almost 15 yearsThanks Marc, my store procedure does not have any parameters. It just does some clean-up work to delete all age out records as I asked in the previous question. In my sample, I just need to enter "exec [dbo].[MyStoreProcedureName]", correct?
-
ZygD almost 15 yearsDatabase context too: Change the Database to "MyDB" or specify the stored proc as EXEC Mydb.dbo.MyProcname
-
Tilting Code over 5 yearsDepending on the schema you may use something like: USE <databaseName> exec (your stored proc name) (and possibly add parameters)