Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top