44

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
George2
  • 44,761
  • 110
  • 317
  • 455

2 Answers2

76

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Thanks 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? – George2 Aug 01 '09 at 10:03
  • 7
    Database context too: Change the Database to "MyDB" or specify the stored proc as EXEC Mydb.dbo.MyProcname – gbn Aug 01 '09 at 11:01
  • Depending on the schema you may use something like: USE exec (your stored proc name) (and possibly add parameters) – Tilting Code Oct 01 '18 at 13:30
3

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

Dan Diplo
  • 25,076
  • 4
  • 67
  • 89