EXCLE导入SQL Server的两个问题
今天遇到一个客户,把自己之前搁置的问题摆到了面前,措手不及下处理起来走了不少弯路,最终也没有完全解决,主要还是技术储备不够。其中有关EXCLE数据导入SQL2000时遇到两个问题,在网上搜索了解决办法,收藏一下:
1、将Excel导入到SQL sever数据库,提示说“外部表不是预期的格式”
可能的原因:有表头、或者是格式上有合并单元格之类的
解决办法:把表中的数据复制一下,使用只粘贴数据到一个新表中,导入新表
(摘自http://zhidao.baidu.com/question/86652526.html?fr=ala1)
2、Excel数据导入Sql Server出现Null
引起的原因:导入为Null的数据列属于混合数据类型列
解决办法:强制解析——IMEX=1(使用 IMEX=1 选参之后,只要取样数据里是混合数据类型的列,一律强制解析为 nvarchar/ntext 文本)
SELECT * INTO Table
from OpenDataSource
('Microsoft.Jet.OLEDB.4.0','Data Source="E:\1.xls";Extended properties="Excel 5.0;HDR=Yes;IMEX=1;"')...[Sheet1$]
(摘自http://hi.baidu.com/hackerxxw/blog/item/b5e5fcde4fb0f45c94ee3798.html)
相关文档:
create PROCEDURE pagelist
@tablename nvarchar(50),
@fieldname nvarchar(50)='*',
@pagesize int output,--每页显示记录条数
@currentpage int output,--第几页
@orderid nvarchar(50),--主键排序
@sort int,--排序方式,1表示升序,0表示降序排列
......
insert into Country123 ([Country_Id], [Region_ID], [Country_EN_Name], [Country], [Country_ALL_ID], [Country_Order_Id]) select [Country_Id], [Region_ID], [Country_EN_Name], [Country], [Country_ALL_ID], [Country_Order_Id] from openrowset( 'Microsoft.Jet.OLEDB.4.0', 'EXCEL 5.0;HDR=YES;IMEX=1; DATABASE= ......
Aaron Bertrand
Adam Machanic
All Things SQL Server
Allen Kinsel - SQL DBA
Allen White
Amit Bansal writes...
Andrew Fryer's Blog
Andrew Kelly
Andy Leonard
Anything and Everything IT
Arcane Code
Arnie Rowland: Ramblings of a Harried Technogeek
B.I. for the SQL Guy
Bart Duncan's SQL Weblog ......
declare
@aa varchar(20)
set @aa= CONVERT(varchar(100), GETDATE(), 23)
--//日
print @aa+' 0:00:00.000'
print @aa+' 23:59:59.999'
--//周
print CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate()), 0), 23)+' 0:00:00.000'
print CONVERT(varchar(100), DATEADD(wk, DATEDIFF(wk,0,getdate( ......