使用“openrowset”的 sql 脚本出错
我的 SQL 脚本有问题:
SELECT
SP.[MobileNumber],
SP.[LastName],
SP.[FirstName]
FROM SampleTable1 SP
INNER JOIN OPENROWSET
(
'Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\devpc11\sample.xls;',
'SELECT
MobileNumber,
LastName,
FirstName
FROM [SampleData$]') T
ON SP.[MobileNumber] = T.[MobileNumber]
GO
当我尝试执行此脚本时,它会生成以下错误:
Msg 7357,Level 16,State 2,Line 1 无法处理对象“SELECT 手机号码, 姓, 名 FROM [SampleData$]”。链接服务器“(null)”的 OLE DB 提供程序“Microsoft.Jet.OLEDB.4.0”表示该对象没有列,或者当前用户对该对象没有权限。
是否有有什么解决方案吗?在过去的3个小时里我真的找不到任何解决方案..基本上,我只想操作excel文件中的数据,然后将其保存到sql server 2005数据库,但现在,我想检索数据从excel文件到sql服务器..感谢您的帮助..
I'm having a problem with my SQL script:
SELECT
SP.[MobileNumber],
SP.[LastName],
SP.[FirstName]
FROM SampleTable1 SP
INNER JOIN OPENROWSET
(
'Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\devpc11\sample.xls;',
'SELECT
MobileNumber,
LastName,
FirstName
FROM [SampleData$]') T
ON SP.[MobileNumber] = T.[MobileNumber]
GO
when i try to execute this, it generates this error:
Msg 7357, Level 16, State 2, Line 1
Cannot process the object "SELECT
MobileNumber,
LastName,
FirstName
FROM [SampleData$]". The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" indicates that either the object has no columns or the current user does not have permissions on that object.
Is there any solution for this? i really can't find any in the past 3 hours.. Basically, i just want to manipulate data from an excel file, then save it to sql server 2005 database, but for now, i want to retrieve data from the excel file to the sql server.. thanks for the help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我让它与本地电子表格一起使用。忘记
OPENROWSET
在 Excel 电子表格中创建命名范围。为此,突出显示所需的列(包括标题),右键单击并选择“命名范围”。为其命名,这将是您的表名称。
http://www.homeandlearn.co.uk/me/mes9p2.html< /a>
保存并关闭您的电子表格。如果您打开它,SQL Server 将无法访问它。
添加链接服务器。请按照下面E 部分中的说明进行操作,该说明告诉您如何为 Excel 电子表格添加链接服务器:
http://msdn.microsoft.com/en-us/library/ ms190479.aspx
您应该能够非常愉快地查询 DS,再次按照指示。
这是适合我的代码:
最后。开始接受一些答案并对任何有帮助的答案进行投票。这是 StackOverflow 的命脉。
I got this to work with a spreadsheet locally. forget
OPENROWSET
Create a named range in your excel spreadheet. Tio do this, highlight the columns (including headers) you want, right-click and select 'Name a range'. Give this a name, this will be your table name.
http://www.homeandlearn.co.uk/me/mes9p2.html
Save and close your spreadsheet. SQL Server wont be able to access it if you hve it open.
Add a linked server. Follow the instructions in Section E in the following which tells you how to add a linked server for Excel Spreadsheets:
http://msdn.microsoft.com/en-us/library/ms190479.aspx
You should be able to query the DS quite happily, again following the instructions.
Here is the code that works for me:
And finally. Start accepting some answers and voting up any helpful ones. This is the lifeblood of StackOverflow.