简体   繁体   English

将SQL查询数据导出到Excel并在网络外部存储excel位置

[英]Export SQL query data to Excel and storing location excel outside network

I have to export the Sql server data into the Excel file and to export data I am using the sql query as 我必须将Sql服务器数据导出到Excel文件中并导出数据,而我正在使用sql query

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
'Excel 8.0;Database=D:\testing.xls;', 
'SELECT * FROM [SheetName$]') select * from SQLServerTable

But In above query I am exporting data into the D drive which is local in my system. 但是在上面的查询中,我将数据导出到系统中本地的D drive中。 What If i have to export data to some other system which is outside my network. 如果我必须将数据导出到网络之外的其他系统怎么办? That system might exist in some other location or company. 该系统可能存在于其他位置或公司。 If i give shared folder in other system with System IP Address and location instead of D drive whether it will work or not. 如果我在其他系统中使用System IP Address and location而不是D drive来提供共享文件夹,则它是否可以工作。 means 手段

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
'Excel 8.0;Database=\\10.10.10.10\ab\A\testing.xls;', 
'SELECT * FROM [SheetName$]') select * from SQLServerTable

Check that user, which excecutes this query can access the file. 检查执行此查询的用户是否可以访问该文件。 Also check is file shared or not? 还检查文件是否共享?

To check is you SQL Server has permition to file excecute 要检查您是否允许SQL Server执行文件执行

EXEC Master.dbo.xp_DirTree '\\10.10.10.10\ab\A\',1,1

If result will show you a list of files, SQL server has permition 如果结果将显示文件列表,则表明SQL Server允许

To use BULK INSERT or INSERT...SELECT * FROM OPENROWSET(BULK...) to bulk import data from another computer, the data file must be shared between the two computers. 若要使用BULK INSERT或INSERT ... SELECT * FROM OPENROWSET(BULK ...)从另一台计算机批量导入数据,必须在两台计算机之间共享数据文件。 To specify a shared data file, use its universal naming convention (UNC) name, which takes the general form, \\Servername\\Sharename\\Path\\Filename. 若要指定共享数据文件,请使用其通用命名约定(UNC)名称,其通用格式为\\ Servername \\ Sharename \\ Path \\ Filename。 Additionally, the account used to access the data file must have the permissions that are required for reading the file on the remote disk. 此外,用于访问数据文件的帐户必须具有读取远程磁盘上的文件所需的权限。

http://technet.microsoft.com/en-us/library/ms175915.aspx http://technet.microsoft.com/zh-CN/library/ms175915.aspx

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

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