当前位置: 首页 > 图文教程 > 数据库 > 数据库技巧 > Select data from an Excel sheet in MSSQL

数据库技巧
数据库设计经验谈
数据库设计的折衷方法
Access与sql server的语法区别总结
收藏的SQLServer技巧集
多种获取远程连接access数据库的方法
SQL中NTEXT字段内容显示<long text>的原因
SQL Prompt--绝好的SQL语法提示工具
海量数据库的查询优化及分页算法方案 2 之 改良SQL语句
海量数据库的查询优化及分页算法方案集合1/2
海量数据库的查询优化及分页算法方案集合2/2
取随机记录的语句
问个高难度的复杂查询(在一个时间段内的间隔查询)
Sql语句求最小可用id
Sql Server 和 Access 操作数据库结构Sql语句小结
ACCESS转化成SQL2000需要注意的几个问题小结
SQL Server数据库性能优化技术
数据库正规化和设计技巧
如何让你的SQL运行得更快
Select data from an Excel sheet in MSSQL
一个多表查询的SQL语句

数据库技巧 中的 Select data from an Excel sheet in MSSQL


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 128 ::
收藏到网摘: n/a

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)