Select data from an Excel sheet in MSSQL
更新時間:2007年06月26日 00:00:00 作者:
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)
相關(guān)文章
淺談為什么數(shù)據(jù)庫字段建議設(shè)置為NOT NULL
本文主要介紹了MySQL數(shù)據(jù)庫中將字段設(shè)置為NOT NULL的性能和優(yōu)缺點,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-12-12
sql優(yōu)化實戰(zhàn) 把full join改為left join +union all(從5分鐘降為10秒)
因為特殊原因,無法訪問客戶的服務(wù)器,沒辦法查看sql的執(zhí)行計劃、沒辦法知道表中的索引情況,所以,嘗試從語句的改寫上來優(yōu)化2020-09-09
neo4j圖數(shù)據(jù)庫安裝實踐與報錯問題的解決
這篇文章主要介紹了neo4j圖數(shù)據(jù)庫安裝實踐與報錯問題的解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
使用Sqlyog遠程連接數(shù)據(jù)庫報錯解決方案
大家好,本篇文章主要講的是使用Sqlyog遠程連接數(shù)據(jù)庫報錯解決方案,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下,方便下次瀏覽2021-12-12

