Sql 脚本导入EXCEL数据

Sql 脚本导入EXCEL数据

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 delete excel

--讀取EXCLE表數
SELECT e_mail  excel FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\Documents and Settings\geovindu\桌面\vip平常按排工作\2010-06-18\2010-06-18.xls;Extended Properties=Excel 8.0')...[Sheet1$]
GO


--讀取EXCLE表數
SELECT e_mail  excel FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\Documents and Settings\geovindu\My Documents\Visual Studio 2005\Projects\Sales\emailList.xls;Extended Properties=Excel 8.0')...[Sheet1$]
GO

--創造新表

SELECT e_mail INTO  excel FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\Documents and Settings\geovindu\My Documents\Visual Studio 2005\Projects\Sales\emailList.xls;Extended Properties=Excel 8.0')...[Sheet1$]
GO

--在原有表插入,EXCEL的單元格列頭名與表名要一致
INSERT INTO excel 
SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\Documents and Settings\geovindu\桌面\vip平常按排工作\2010-06-18\2010-06-18.xls;Extended Properties=Excel 8.0')...[Sheet1$]
GO
SELECT * FROM excel

DELETE excel WHERE e_mail is null

drop table vipEmail
select vipno,e_mail into vipEmail from excel

select * from vipEmail
---
SELECT e_mail INTO excel FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\Documents and Settings\geovindu\My Documents\Visual Studio 2005\Projects\Sales\emailList.xls;Extended Properties=Excel 8.0')...[Sheet1$]

 

select * from openrowset('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:\Documents and Settings\geovindu\My Documents\Visual Studio 2005\Projects\Sales\emailList.xls','select * from [''Sheet1$'']')

你可能感兴趣的:(SQL,Server,2000/2005/2008)