如何在SQL Server代理作业中将值从一个步骤(T-SQL)传递到另一步骤 [英] How values will get passed from one step(T-SQL) to another in SQL Server Agent Jobs

查看:80
本文介绍了如何在SQL Server代理作业中将值从一个步骤(T-SQL)传递到另一步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SQL Server作业定期将邮件发送给用户.我必须从数据库中获取详细信息,在第一步中,我将获取配置为获取邮件的用户的详细信息,在第二步中,我将使用必须读取第一步值的存储过程.值如何从一个步骤传递到另一步骤?我们是否需要在每个步骤中创建输出文件来读取值?
如何使用sp_add_jobserver连接到各种服务器(将从数据库表中获取服务器详细信息)?</pre>

I want to send mails to users in a regular interval of time using SQL Server jobs. I have to fetch details from database, in first step I''m fetching details of users who configured to get mail, in second step I''m using stored procedure that must read the values of first step. How values will get passed from one step to another? Do we need to create output file in each step to read values?
How to use sp_add_jobserver to connect to various servers (server details will be fetched from database table)?</pre>

推荐答案

一个选项是创建临时保存表来保存数据.

创建一个随机表名称
检查表名是否存在,是否重试
创建临时表,执行查询并插入到临时表
然后下一步便有了数据.

确保作业步骤失败或成功完成,但是您有适当的清理步骤来删除临时表.
One option is to create temporary holding tables to hold the data.

Create a random table name
Check if a table name exists, if it does try again
create the temporary table, perform your query and insert to temp table
then in the next step you have the data.

Make sure though if the job step fails or completes successfully, you have suitable clean up step to remove the temporary table.


这篇关于如何在SQL Server代理作业中将值从一个步骤(T-SQL)传递到另一步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆