您的位置:首页 > 数据库

一个向sql server 2005导入excell的存储过程

2009-06-05 23:57 381 查看
if exists(select name from sysobjects
where name='import_excell' and type='P')
drop proc import_excell
go
create proc import_excell @table nvarchar(255),@path nvarchar(255), @sheetName nvarchar(255)
as
begin
exec sp_configure 'show advanced options',1
reconfigure WITH OVERRIDE
exec sp_configure 'xp_cmdshell', 1
RECONFIGURE WITH OVERRIDE
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure WITH OVERRIDE

declare @sql nvarchar(1000)
select @sql='delete ' + @table
exec sp_executesql @sql
select @sql='insert into '+@table+' select * FROM OpenDataSource( ''Microsoft.Jet.OLEDB.4.0'',''Data Source="'
+@path+'";User ID=Admin;Password=;Extended properties=Excel 8.0'')...['
']+@sheetName+'$]'
exec sp_executesql @sql
end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: