t-sql read xlsx

1936 단어 t-sql
How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility
To read an Excel 2007 or Excel 2010 file using OPENROWSET, run the following query:
SELECT * 

FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',

'Excel 12.0;Database=C:\YourFile.xlsx;',

'SELECT * FROM [Sheet1$]')

If the Excel 2007 or Excel 2010 file does not contain any headers, simply add the “HDR=No” to the OPENROWSET command as follows:
SELECT * 

FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',

'Excel 12.0;Database=C:\YourFile.xlsx;HDR=No',

'SELECT * FROM [Sheet1$]')

If one of the columns in the Excel 2007 or Excel 2010 file contains a mixed type of data, where some rows may contain just numbers while others may contain alphanumeric values, add the “IMEX=1” to the second parameter of the OPENROWSET command, as follows:
SELECT * 

FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',

'Excel 12.0;Database=C:\YourFile.xlsx;IMEX=1',

'SELECT * FROM [Sheet1$]')

To load the Excel 2007 or Excel 2010 data to a new SQL Server table, simply add the INTO clause of the SELECT statement as follows:
SELECT * 

INTO [dbo].[MyExcelData]

FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',

'Excel 12.0;Database=C:\YourFile.xlsx;',

'SELECT * FROM [Sheet1$]')

we must set adhocremotequeriesenabled = true :
right click the database and choose facets the link is :
http://www.mssqltips.com/sqlservertip/1673/where-is-the-surface-area-configuration-tool-in-sql-server-2008/

좋은 웹페이지 즐겨찾기