I need to import an excel spreadsheet into SQL Server 2005. What steps would I need to take to accomplish that?
Microsoft Excel workbooks are one type of OLE DB data source that you can query through SQL Server in this manner.
An alternative quick and (very) dirty solution is to add a formula to the excel sheet, like this:
="INSERT INTO table1(col1, col2, col3) SELECT " & A1 & ", '" & B1 & "', '" & C1 & "'"
Copy this down (CTRL+D) and you're good to go.
The "Data Transformation Services" wizards are your friend.
The instructions here assume SQL Server 2000
Depending on what you want to do with the data, you have a few options new. For one-off jobs I generally find it easiest to import all the excel data, then edit it in SQL Server, but if you're going to repeat this action on multiple files, you might want to craft a really sexy import script.
If you are going to run it again, you can save the DTS package using the wizard, then edit it in the "Data Transformation Services" section of Enterprise Manager. It's a good way to learn how DTS works.
you can also do it with OPENROWSET
INSERT INTO SOMETABLE SELECT * FROM OPENROWSET( 'Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\testing.xls','SELECT * FROM [Sheet1$]')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With