使用输入参数为存储过程创建 SQL Server 代理作业

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35633687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:27:30  来源:igfitidea点击:

Create SQL Server Agent job for stored procedure with input parameter

sqlsql-servertsqlstored-proceduressql-agent-job

提问by stoner

Could you suggest please how to create SQL Server Agent job for a stored procedure that have 1 input parameter?

您能否建议如何为具有 1 个输入参数的存储过程创建 SQL Server 代理作业?

The procedure is correctly created and i executed it using this code :

该过程已正确创建,我使用以下代码执行它:

EXECUTE dbo.MYProcedure N'2016-02-25';

Is there a way to create a SQL Server Agent job for this procedure that have parameter ?

有没有办法为此具有参数的过程创建 SQL Server 代理作业?

So i'm trying the basic way that is add this ligne in EXECUTE dbo.MYProcedure N'2016-02-25';to the window of step in job But the paraméter can change

所以我正在尝试将这个 ligne 添加EXECUTE dbo.MYProcedure N'2016-02-25';到工作步骤窗口的基本方法 但是参数可以改变

回答by MsCoder

here are the steps

这是步骤

  1. in SQL management studio, right click on "SQL Server Agent" under the SQL server which you are connected to.
  2. Select New Job.
  3. Enter the job name and then click on steps
  4. Click on "New" which should be right at the bottom of the screen.
  5. Enter step name.
  6. Type: keep it selected as Transact SQL
  7. Enter : EXECUTE dbo.MYProcedure N'2016-02-25';
  1. 在 SQL management studio 中,右键单击您所连接的 SQL Server 下的“SQL Server Agent”。
  2. 选择新建作业。
  3. 输入作业名称,然后单击步骤
  4. 单击屏幕底部的“新建”。
  5. 输入步骤名称。
  6. 类型:保持选择为 Transact SQL
  7. 输入:EXECUTE dbo.MYProcedure N'2016-02-25';

Now save it and it should be ready for running manually. If you do want to automate it then open the job by going into the job monitor under SQL Server Agent in SQL management studio and then click on schedule and provide when and how often you would like your job to run.

现在保存它,它应该可以手动运行了。如果您确实想要自动化,则通过进入 SQL management studio 中 SQL Server Agent 下的作业监视器打开作业,然后单击计划并提供您希望作业运行的时间和频率。

If you automating the date parameter then add this as your Transact SQL statement:

如果您自动化日期参数,则将其添加为您的 Transact SQL 语句:

DECLARE @DATE DATETIME
--Trim out the time so the date is set to 2016/02/25
--and time changes to 00:00 get date will get todays
--date or the run date
SET @DATE = DATEADD(DD,0,DATEDIFF(DD,0,GETDATE()))
EXECUTE dbo.MYProcedure @DATE

Happy coding!!!

快乐编码!!!