Get Excel sheet into temp table using a script

前端 未结 3 1359
北恋
北恋 2020-12-10 14:13

Im trying to get this excel sheet into a table, so I can apply select statements to it etc, to update tables with its info.

SELECT * 
FROM OPENROWSET(\'Micro         


        
3条回答
  •  忘掉有多难
    2020-12-10 15:03

    Just in case someone else stumbles upon this years later like I did, this is what worked for me:

    We had a box that had SQL Server Express 2012 on a Windows 8 64 bit machine with no version of Office installed.

    Here is part of my stored proc I setup:

    INSERT INTO OPENROWSET ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=R:\Export Membership Database\Member_Export.xls;',
    'SELECT * FROM [combined$]')
    

    (the rest of the SELECT statement below this)

    I received this error:

    SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', search for 'Ad Hoc Distributed Queries' in SQL Server Books Online.

    We changed the configuration:

    sp_configure 'show advanced options', 1;
    GO
    RECONFIGURE;
    GO
    sp_configure 'Ad Hoc Distributed Queries', 1;
    GO
    RECONFIGURE;
    GO
    

    Ran the stored proc again and then got this error:

    The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered.

    Found we needed to install this:

    http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c06b8369-60dd-4b64-a44b-84b371ede16d&displaylang=en

    After that, worked like a charm!

提交回复
热议问题