把XLS数据弄到SQL的存储过程有点问题,求解
CREATE PROCEDURE readexceldata
declare @filename varchar(200)
set @filename= 'e:\a.xls '
declare @exceltablename varchar(20)
set @exceltablename= 'sheet1 '
declare @tablename varchar(200),
set @tablename= 'b '
as
declare @sql varchar(1000)
set @sql= ' insert into '+@tablename+
' SELECT * '+
' FROM OpenDataSource( ' 'Microsoft.Jet.OLEDB.4.0 ' ', ' 'Data Source= '+@filename+
';User ID=Admin;Password=;Extended properties=Excel 5.0 ' ')...[ '+@exceltablename+ '] '
exec(@sql)
go
老是报错,说as 和 set 附近语法有问题...
另外,我如果每5秒要运行这个过程的话,是不是在作业里设置?
------解决方案--------------------CREATE PROCEDURE readexceldata
as --少as
declare @filename varchar(200)
set @filename= 'e:\a.xls '
declare @exceltablename varchar(20)
set @exceltablename= 'sheet1 '
declare @tablename varchar(200) --去掉,
set @tablename= 'b '
--去掉as
declare @sql varchar(1000)
set @sql= ' insert into '+@tablename+
' SELECT * '+
' FROM OpenDataSource( ' 'Microsoft.Jet.OLEDB.4.0 ' ', ' 'Data Source= '+@filename+
';User ID=Admin;Password=;Extended properties=Excel 5.0 ' ')...[ '+@exceltablename+ '] '
exec(@sql)
go