create table #t(fname varchar(260),depth int,isf bit)
insert into #t exec master..xp_dirtree 'c:\test\',1,1
declare tb cursor for select fn='c:\test\'+fname from #t
where isf=1 and fname like '%.xls' --取.xls文件(EXCEL)
declare @fn varchar(8000)
open tb
fetch next from tb into @fn
while @@fetch_status=0
begin
set @fn='select * from
OPENROWSET(''MICROSOFT.JET.OLEDB.4.0'',''Excel 5.0;HDR=YES;DATABASE='+@fn+''',合同表$)' --这里只是查询出来,你要改为insert
exec(@fn)
fetch next from tb into @fn
end
close tb
deallocate tb
drop table #t