简体   繁体   English

如何使用 SQL 作业将数据导出到 SQL Server 中的 Excel

[英]How to Export data to Excel in SQL Server using SQL Jobs

I need to export the data from a particular table in my database to Excel files (.xls/.xlsx) that will be located into a shared folder into my network.我需要将数据库中特定表中的数据导出到 Excel 文件 (.xls/.xlsx),该文件将位于网络的共享文件夹中。 Now the situation is like this -现在的情况是这样——

  1. I need to use SQL SERVER Agent Jobs.我需要使用 SQL SERVER 代理作业。 2.I need to generate a new excel file in every 2 minutes that will contain the refreshed data. 2.我需要每 2 分钟生成一个包含刷新数据的新 Excel 文件。

    I am using sql server 2008 that doesn't include BI development studio.我正在使用不包含 BI 开发工作室的 sql server 2008。 I'm clueless how to solve this situation.我不知道如何解决这种情况。 First, I'm not sure how to export the data using jobs because every possible ways I tried had some issues with the OLEDB connection.首先,我不确定如何使用作业导出数据,因为我尝试过的每一种可能的方法都存在一些与 OLEDB 连接有关的问题。 The 'sp_makewebtask' is also not available in SQL 2008. And I'm also confused how to dynamically generate the names of the files. 'sp_makewebtask' 在 SQL 2008 中也不可用。我也很困惑如何动态生成文件的名称。

    Any reference or solution will be helpful.任何参考或解决方案都会有所帮助。

Follow the steps given below :请按照以下步骤操作:

1) Make a stored procedure that creates a temporary table and insert records to it. 1)创建一个存储过程,创建一个临时表并向其中插入记录。

2) Make a stored procedure that read records from that temporary table and writes to file. 2)创建一个存储过程,从该临时表中读取记录并写入文件。 You can use this link : clickhere您可以使用此链接: 单击此处

3) Create an SQL-job that execute step 1 and step 2 sequentially. 3) 创建一个 SQL 作业,依次执行步骤 1 和步骤 2。

I found a better way out.我找到了更好的出路。 I have created a SSIS(SQL Server Integration Services) package to automate the whole Export to Excel task.我创建了一个 SSIS(SQL Server 集成服务)包来自动化整个导出到 Excel 任务。 Then I deployed that package using SQL Server Agent Jobs.然后我使用 SQL Server 代理作业部署了该包。 This is a more neat and clean solution as I found.正如我发现的那样,这是一个更整洁的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM