欢迎来到福编程网,本站提供各种互联网专业知识!

Select data from an Excel sheet in MSSQL

发布时间:2007-06-26 作者: 来源:转载
select*fromopenrowset('Microsoft.Jet.OLEDB.4.0','Excel8.0;HDR=YES;IMEX=1;DATABASE=d:\folder\excel.xls',Sheet1$)-------NOTE------SettingIMEX=1tellsthedrivertouseImportmode.Inthisstate,theregistrysettingImportMixedTypes=Textwillben
select*
fromopenrowset('Microsoft.Jet.OLEDB.4.0'
,'Excel8.0;HDR=YES;IMEX=1;DATABASE=d:folderexcel.xls',Sheet1$)

-------NOTE------
SettingIMEX=1tellsthedrivertouseImportmode.Inthisstate,theregistrysettingImportMixedTypes=Textwillbenoticed.Thisforcesmixeddatatobeconvertedtotext.Forthistoworkreliably,youmayalsohavetomodifytheregistrysetting,TypeGuessRows=8.TheISAMdriverbydefaultlooksatthefirsteightrowsandfromthatsamplingdeterminesthedatatype.Ifthiseightrowsamplingisallnumeric,thensettingIMEX=1willnotconvertthedefaultdatatypetoText;itwillremainnumeric.

YoumustbecarefulthatIMEX=1notbeusedindiscriminately.ThisisIMPORTmode,sotheresultsmaybeunpredictableifyoutrytodoappendsorupdatesofdatainthismode.

ThepossiblesettingsofIMEXare:
0isExportmode
1isImportmode
2isLinkedmode(fullupdatecapabilities)

相关推荐