Pregunta

Estoy teniendo un problema con mi secuencia de comandos 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

Cuando trato de ejecutar esto, se genera este error:

Msg 7357, nivel 16, estado 2, línea 1 No se puede procesar el objeto "SELECT Número de teléfono móvil, Apellido, Nombre de pila DE [SampleData $]". El proveedor OLE DB 'Microsoft.Jet.OLEDB.4.0' para el servidor vinculado '(null)' indica que o bien el objeto no tiene columnas o el usuario actual no tiene permisos en ese objeto.

¿Hay alguna solución para esto? Realmente no puedo encontrar ninguna en los últimos 3 horas .. Básicamente, sólo quiero manipular los datos de un archivo de Excel, a continuación, guárdelo a la base de datos de SQL Server 2005, pero por ahora, quiero recuperar datos del archivo de Excel a el servidor SQL .. gracias por la ayuda ..

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top