Select data from an Excel sheet in MSSQL
程序员文章站
2022-05-04 16:12:35
select * from openrowset('microsoft.jet.oledb.4.0' ,'excel 8.0;hd...
select *
from openrowset('microsoft.jet.oledb.4.0'
,'excel 8.0;hdr=yes;imex=1;database=d:\folder\excel.xls',sheet1$)
-------note------
setting imex=1 tells the driver to use import mode. in this state, the registry setting importmixedtypes=text will be noticed. this forces mixed data to be converted to text. for this to work reliably, you may also have to modify the registry setting, typeguessrows=8. the isam driver by default looks at the first eight rows and from that sampling determines the datatype. if this eight row sampling is all numeric, then setting imex=1 will not convert the default datatype to text; it will remain numeric.
you must be careful that imex=1 not be used indiscriminately. this is import mode, so the results may be unpredictable if you try to do appends or updates of data in this mode.
the possible settings of imex are:
0 is export mode
1 is import mode
2 is linked mode (full update capabilities)
from openrowset('microsoft.jet.oledb.4.0'
,'excel 8.0;hdr=yes;imex=1;database=d:\folder\excel.xls',sheet1$)
-------note------
setting imex=1 tells the driver to use import mode. in this state, the registry setting importmixedtypes=text will be noticed. this forces mixed data to be converted to text. for this to work reliably, you may also have to modify the registry setting, typeguessrows=8. the isam driver by default looks at the first eight rows and from that sampling determines the datatype. if this eight row sampling is all numeric, then setting imex=1 will not convert the default datatype to text; it will remain numeric.
you must be careful that imex=1 not be used indiscriminately. this is import mode, so the results may be unpredictable if you try to do appends or updates of data in this mode.
the possible settings of imex are:
0 is export mode
1 is import mode
2 is linked mode (full update capabilities)