如何写语句把excel文档里的内容导入到库里面?
库里有表为yb_item
CREATE TABLE [dbo].[yb_item] (
[dm] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[dmmc] [varchar] (250) COLLATE Chinese_PRC_CI_AS NULL ,
[pym] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[wbm] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[ybm] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[sfzl] [varchar] (3) COLLATE Chinese_PRC_CI_AS NULL ,
[fplb] [varchar] (3) COLLATE Chinese_PRC_CI_AS NULL ,
[fpmc] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[cfbz] [varchar] (3) COLLATE Chinese_PRC_CI_AS NULL ,
[zfbl] [decimal](18, 4) NULL ,
[jx] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[ypxh] [int] IDENTITY (1, 1) NOT NULL
) ON [PRIMARY]
GO
相应的有个对应的excel文档,字段都是一一对应的。想把excel里的内容导入到这个表中,如何写语句实现?而不使用数据的导入导出功能。
[解决办法]
insert into yb_item select * from opendatasource( 'Microsoft.Jet.OLEDB.4.0 ',
'Data Source= "d:\test.xls ";
User ID=Admin;Password=;Extended properties=Excel 5.0 ')...sheet1$(f1)
[解决办法]
insert into yb_item select * from opendatasource( 'Microsoft.Jet.OLEDB.4.0 ',
'Data Source= "d:\test.xls ";
--
1
insert into 表1
select * from 表2
以上是从表2向表1插入的基本格式
2
opendatasource( 'Microsoft.Jet.OLEDB.4.0 ',
'Data Source= "d:\test.xls ";
表2换成了外部的数据源,
'Microsoft.Jet.OLEDB.4.0 '是数据驱动
'Data Source= "d:\test.xls是路径
User ID=Admin;Password=;Extended properties=Excel 5.0 ')...sheet1$
--用户名,密码,sheet1是execel中的第一页