OPENROWSET with spaces in sheet name

  • Hi All,

    I'm trying to use the following statement to import data from an excel worksheet into sql, but I haven't been able to get the syntax right, since the source worksheet contains spaces in the tab name. I have tried:

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=P:\Statements\Activity20100422.xls',Trade Date Detail$)

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=P:\Statements\Activity20100422.xls',[Trade Date Detail$])

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=P:\Statements\Activity20100422.xls',[Trade Date Detail]$)

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=P:\Statements\Activity20100422.xls','Trade Date Detail'$)

    But I always get the error:

    The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" does not contain the table "Trade Date Detail$". The table either does not exist or the current user does not have permissions on that table.

    I'd greatly appreciate any help on this.

    Many thanks in advance!

  • Retry the second one prepended with "SELECT * FROM "

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=P:\Statements\Activity20100422.xls','SELECT * FROM [Trade Date Detail$]')

  • Hi,

    For me this works

    SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=P:\Statements\Activity20100422.xls',['Trade Date Detail$'])

    PetrPan

  • Hi Petr,

    that worked for me, too, thx.

    ... after I closed the excel file that is... 🙂

Viewing 4 posts - 1 through 3 (of 3 total)

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