How to import data from Excel file on local machine to Sql Server using Query

  • Hi !

    I am trying to import excel table into my sql database.

    My excel file is on my local machine and I tried this code :

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=Q:\Documents and Settings\Administrator\My Documents\myfile.xls', 'SELECT * FROM [QPrintPolicyRenew$]')

    I keep getting this error :

    Cannot get the column information from OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

    Can anyone help ??

  • This might help you.

    http://www.sql-server-helper.com/tips/read-import-excel-file-p02.aspx

    Basically you need to add to your openrowset command is: ;HDR=No

    Excel 8.0;DATABASE=c:\temp\items.xls;IMEX=1;HDR=No

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Thanks for your reply !

    I've tried this :

    SELECT *

    FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',

    'Excel 8.0;Database=Q:\Documents and Settings\Administrator\My Documents\myfile.xls;IMEX=1;HDR=No',

    'SELECT * FROM [QPrintPolicyRenew$]')

    and I'm still getting this :

    Cannot get the column information from OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

  • gil_500

    Is the EXCEL work book on the same server as is your instance of SQL Server?

    It should be noted that the Excel file must be located in the SQL Server where you are connected and not on your local machine. The C: drive specified in the OPENROWSET function is the C: drive of the SQL Server you are connected to and not your local C: drive.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Your server Is 32-Bit or 64-Bit?

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply