error on sql script with 'openrowset'

谁说胖子不能爱 提交于 2019-12-06 13:41:28

I got this to work with a spreadsheet locally. forget OPENROWSET

  1. 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

  2. Save and close your spreadsheet. SQL Server wont be able to access it if you hve it open.

  3. 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

  4. You should be able to query the DS quite happily, again following the instructions.

Here is the code that works for me:

EXEC sp_addlinkedserver 'ExcelSource4',
   'Jet 4.0',
   'Microsoft.Jet.OLEDB.4.0',
   'c:\sqlss.xls',
   NULL,
   'Excel 5.0';
GO

SELECT *
   FROM ExcelSource4...MyTable2;

And finally. Start accepting some answers and voting up any helpful ones. This is the lifeblood of StackOverflow.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!