如何自动将Sql查询结果导出到数据透视表中 [英] How Do I Export Sql Query Result Into Pivot Table Automatically
问题描述
嗨
我想将我的sql查询结果保存为excel(pivot)文件。
我使用以下代码:
Hi
I want to save my sql query result as excel(pivot) file.
I use from below code:
insert into OPENROWSET
('Microsoft.ACE.OLEDB.12.0',
'EXCEL 12.0 Xml;Database=C:\Test.xlsx;HDR=YES;','SELECT * FROM [sheet1$]')
select * from SalesItem
在此之前,每次我需要创建excel文件并在其中添加列。它可以正常工作但创建正常的Excel文件。
但是我需要在指定的文件夹和每个月的开头自动创建excel数据文件(每个月的单独文件)。如何为我的查询传递月份和年份。
我正在使用 SQL server 2008 R2 32位和Office 2010标准。
Before this, every time i need to create excel file and add columns in it.which works fine but creates normal Excel file.
But I need to create excel pivot file automatically in a specified folder and at the beginning of every month(separate file for every month).How can i pass month and year for my query.
I am using SQL server 2008 R2 32-bit and Office 2010 standard.
推荐答案
')
选择 * 来自 SalesItem
') select * from SalesItem
在此之前,每次我需要创建excel文件并在其中添加列。它可以正常工作但创建正常的Excel文件。
但是我需要在指定的文件夹和每个月的开头自动创建excel数据文件(每个月的单独文件)。如何为我的查询传递月份和年份。
我正在使用 SQL server 2008 R2 32位和Office 2010标准。
Before this, every time i need to create excel file and add columns in it.which works fine but creates normal Excel file.
But I need to create excel pivot file automatically in a specified folder and at the beginning of every month(separate file for every month).How can i pass month and year for my query.
I am using SQL server 2008 R2 32-bit and Office 2010 standard.
在SQL Server中创建一个表来保存你的表转移数据并将其导出为excel。
Create a table in SQL server that holds your pivoted data and export that to excel.
这将帮助您.... http://stackoverflow.com/questions/7674786/mysql-pivot-table [ ^ ]
This Will Help you....http://stackoverflow.com/questions/7674786/mysql-pivot-table[^]
这篇关于如何自动将Sql查询结果导出到数据透视表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!